Ajax asynchronous request function error, many browsers cannot succeed, prompt is not a function

Source: Internet
Author: User
RT, I'm working on the PHP page.
Only IE browser success, my left column is the option, and then the right column according to the left side of the asynchronous request display, with the JS
var xmlhttp = null;
function Getxmlhttprequest () {
var xmlHttp = null;
try{
XmlHttp = new Xmlhttpreqeust ();
}
catch (e) {
try{
XmlHttp = new ActiveXObject ("Msxml2.xmlhttp");

}
catch (e) {
try{
XmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (e) {
XmlHttp = false;
}
}
}
return xmlHttp;
}
XMLHTTP = Getxmlhttprequest ();
$ (' showallnodes '). onclick = function () {

Xmlhttp.open (' GET ', ' node/allnodes.php ', true);
Xmlhttp.onreadystatechange = Showclass;
Xmlhttp.send (NULL);
}
This is the Ajax code, with IE can be displayed, the other parts of the code should be no problem,
I tried 360 (although using the other kernel, but still more common browser bar,,,), Chrome,edge, etc. are prompted
manage.js:57 uncaught TypeError:xmlhttp.open is not a function
Thank you
There is the use of IE can be displayed, but every time I changed a bit of code IE will not take effect, feel there is a cache, I every time I know the browser can be refreshed to the latest effect, other browsers do not exist this problem, immediately effective


Reply to discussion (solution)

try {xmlhttp = new XMLHttpRequest ();} catch (oc) {try {xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");} catch (OC) {}}
Your xmlHttp = new xmlhttpreq eust (); Wrong writing.

IE has a cache, you can add a random value to the URL
It's best to send a blocked cache header in PHP
Header ("Expires:mon, Jul 1997 05:00:00 GMT");    Date in the Pastheader ("Last-modified:". Gmdate ("D, D M Y h:i:s"). "GMT"); Header ("Cache-control:no-cache, must-revalidate");  Http/1.1header ("Pragma:no-cache");                          http/1.0

Browser compatibility is a lot of problems, it is best to use a framework such as JQuery, to avoid unnecessary trouble
After all, you're not a full-time developer.

Thank you, for the above moderator reply to the request of the wrong one is I did not pay attention to the wrong, caching mechanism thank you for pointing Ah,
I'll try the jquery framework again.
For me to meet this situation and solve, can you give me a hint, thank you!!!

Yours
XMLHTTP = Getxmlhttprequest ();
$ (' showallnodes '). onclick = function () {

Xmlhttp.open (' GET ', ' node/allnodes.php ', true);
Xmlhttp.onreadystatechange = Showclass;
Xmlhttp.send (NULL);
}
Writing in JQuery is
$ (' #showallnodes '). Click (function () {
$.get (' node/allnodes.php ', showclass);
})

I found that the problem is that the method is wrong, async method is not a problem, but how to show Ah, I follow the example of human code
Is there a problem with this return method, I use the browser debug found 200, the asynchronous method call succeeded,
But how can it not show?
function Showclass () {
if (xmlhttp.readystate = = 4) {
if (Xmlhttp.status = = 200) {
$ (' ShowMenu '). InnerHTML = Xmlhttp.responsetext;
}
}
}
This is the ID of the div in my right column,
The Open PHP page has this
Header (' Content-type:text/html;charset=utf-8 ');
Right Ah, how to show not come out Ah, before the call IE can also, but now IE also show not come out, async method returned 200, should be no problem, how to show Ah
Thank you

  • 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.