Issues related to Ajax

Source: Internet
Author: User
Issues with Ajax
var xmlHttp;
function S_xmlhttprequest () {
if (window. ActiveXObject) {
Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");

}
else if (window. XMLHttpRequest) {
Xmlhttp=new XMLHttpRequest ();

}
}

function Myajax (URL) {

S_xmlhttprequest ();
Xmlhttp.open ("GET", "for.php?id=" +url,true);
Xmlhttp.onreadystatechange=byphp ();
Xmlhttp.send (NULL);
}

function byphp () {

var Byphp1=xmlhttp.responsetext;

document.getElementById ("PHP"). innerhtml= "Test";
}

The previous two functions are all right. There is a problem with the last function. I put Var byphp1=xmlhttp.responsetext this sentence after the last foreground can display test, but with the Var byphp1=xmlhttp.responsetext, the page is displayed error.


The content of for.php is
if ($id =$_get[' id ') {
for ($i =1; $i <10; $i + +) {
echo $id;
}
Exit ();
}
?>


------Solution--------------------
Did you write the wrong code? Remember knot stickers! Sent more than 10 minutes to find the error! Write you a complete, your for.php page does not change

PHP code
 test with a click Trigger!--suspect you're calling it wrong, you're not going to call byphp.--> 
----- -Solution--------------------
Install Firefox +firebug, can debug JS where there are errors.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.