Jump to content

Recommended Posts

So here's my setup:

 

Xammp/Apache on localhost:80 (target directory is my project folder)

Visual Studio running also on localhost but on some other port

 

So my aspx page runs and then UserInfo.js makes contact with main.php running off of apache.

 

After my ajax runs and makes contact with the php, in IE, I get a status of 200 and OK. Then, the value I want is displayed fine.

 

In Firefox I see:

 

Status: 0

Status Text: OK

data is null

[break on this error] window.alert(data.getElementsB...childNodes[0].nodeValue.toString());  (from firebug)

 

In Chrome I see:

 

Status: 0

Status Text: ""

 

So pretty much, everything works bea

 

UserInfo.js

 

/* create XMLHttpRequest objects for retrieving most searched for games*/


require_once('jquery-1.3.2.js');
require_once('main.php');

function createTest() {
    var xmlHTTP;
    try { xmlHTTP = new XMLHttpRequest(); }
    catch (e) {
        try { xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e) {
            try { xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP"); }
            catch (e) {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    return xmlHTTP;
}

function loadAjax() {
    
    var ajaxObject = createTest();

    if (ajaxObject) {

        
            var fadeDiv = document.getElementById('fade_div');

            ajaxObject.open('GET', 'http://localhost/main.php', true);
          
            ajaxObject.onreadystatechange = function () {
                getUserAccountInformation(ajaxObject);
            }
           
            ajaxObject.send(null);

    }
}

function getUserAccountInformation(ajaxObject) {

    if (ajaxObject.readyState == 4) {
        window.alert("Status: " + ajaxObject.status);
        window.alert("Status Text: " + ajaxObject.statusText);
        var data = ajaxObject.responseXML;
        /*if ((ajaxObject.status == 200) || (ajaxObject.status == 304)) {
           
        
        //window.alert("Finally");*/
       
        window.alert(data.getElementsByTagName("User")[0].childNodes[0].nodeValue.toString());
    }
        /*}
    }
    else {
        document.getElementById('ad_Header_Content').disabled;

    }*/

}

 

Main.php

 

 

<?php
    require_once('main.class.php');
    $main = new Main();
    echo $main->getUserInfo();	  
?> 

 

Main.Class.php

 

 

<?php

require_once('config.php');

class Main{


// constructor opens database connection
function __construct()
{
}

// destructor closes database connection
public function __destruct()
{

}

public function getUserInfo(){

	$db_name = "aspnetdb";

	$connection = mssql_connect ($DB_HOST,'cob','password1') or die ('MsSQL connect failed');	

        mssql_select_db($db_name, $connection);

	$query = 'SELECT fName FROM user_Account_Info';	

	$result = mssql_query($query);

	header("Content-Type: text/xml");
	$output = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
	$output .= '<response>';

		while($row = mssql_fetch_assoc($result))
		{
			$output .= '<User>' . $row['fName'] . '</User>';

		}

	$output .= '</response>';

	return $output;

}
}
?>

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/198710-ajax-working-in-everything-but-ie/
Share on other sites

Firstly, did you get cut off mid sentence or what? You never actually finished your post.

 

Secondly, your code is all over the place. You appear to be trying to use php's require_once() (without <?php tags) within your UserInfo.js script. Is your server configured to do this? If your server is configured to parse php within a js file your php still needs to be within <?php ?> tags. Why would you also be including main.php though?

 

Thirdly, you also appear to (well, at least attempt to) include jQuery into your script then continue to use your own Ajax implementation. Why?

Never mind then I guess, delete the post. Instead of getting an answer, I got a reply focusing on me forgetting to clean up a few lines of code, equivalent to someone asking a question and getting a reply fixing their grammar.

That would make sense if your grammar is very poor and no one can understand what you're saying. It's your own fault for posting bad code. We can't assume that you simply just forgot to clean them up when you posted them. For all we know, those simple mistakes may have been the cause of your issue.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.