Forum Moderators: open

Message Too Old, No Replies

XML problem

         

MartinWeb

5:37 pm on Feb 13, 2010 (gmt 0)

10+ Year Member



Does this code look good? I never get a response

var xmlhttp;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
}
}
var url = "test.php"+";
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

daveVk

12:55 am on Feb 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[webmasterworld.com...]

is prefered way to get xmlhttp

make sure xmlhttp is a global var

make sure following line corrected
var url = "test.php"+";

MartinWeb

7:01 pm on Feb 14, 2010 (gmt 0)

10+ Year Member



If I switch it to the link that you showed me where do I receive and where do I input the URL? Thanks for your help.

daveVk

10:43 pm on Feb 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Replace the first part of your code with call to getXHR()

ie

// first section
var xmlhttp = getXHR();
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{ ... do something with reply ..
}
}
...
// second section
var url = "test.php";
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

The first section should have global scope, say following script tag.

The second section asks for test.php, you will probably not want to do this until at least the page has loaded.

Fotiman

3:01 pm on Feb 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I never get a response

If you navigate directly to test.php, do you get a response? Do you mean that the code where "... do something with reply ..." is never gets executed?

MartinWeb

3:07 am on Feb 22, 2010 (gmt 0)

10+ Year Member



When I go directly to test.php, then the code on the "test.php" page is executed. When I JS code, either the "test.php" code does not execute, or the JS code does not recieve the response.

daveVk

3:47 am on Feb 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To narrow it done try alerts here

xmlhttp.onreadystatechange=function()
alert('readyState:'+xmlhttp.readyState);
{
if(xmlhttp.readyState==4)
{ ... do something with reply ..
}
}
...
// second section
var url = "test.php";
xmlhttp.open("GET",url,true);
alert('send to:'+url);
xmlhttp.send(null);

If possible check server log to see if recv'd