Ajax asynchronous request function error. many browsers cannot succeed, and isnotafunction is prompted.

Source: Internet
Author: User
Ajax asynchronous request function error, many browsers fail, prompting isnotafunction rt. I am working on php web page
Only the IE browser is successful. my left sidebar is an option, and the right sidebar is displayed based on the asynchronous request on the left. js is used.
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 code in ajax. it can be displayed in ie. the code in other parts should be correct,
I tried 360 (although other kernels are used, they are still commonly used browsers.), chrome, edge, and so on.
Manage. js: 57 Uncaught TypeError: xmlhttp. open is not a function
Thank you ,,,
The other is that although ie can be displayed, I don't get the code ie to take effect every time I change it. I feel that there is cache. I can refresh the latest results every time I know the browser, this problem does not exist in other browsers and takes effect immediately.


Reply to discussion (solution)

try {xmlhttp = new XMLHttpRequest();} catch (oc) {try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");} catch (oc) {}}
Your xmlHttp = new XMLHttpReq eust (); is wrong

IE has a cache. you can add a random value to the url.
It is best to send a blocking cache header in php
header ("Expires: Mon, 26 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

There are many browser compatibility problems. it is best to use a framework such as JQuery to avoid unnecessary troubles.
After all, you are not dedicated to frontend development.

Thank you! I didn't pay attention to the error message for the Request replied by the moderator above. thank you for your advice on the cache mechanism,
Let me try the jQuery framework again,
Can you give me some advice on how to solve this problem? thank you !!!

Your
Xmlhttp = GetXmlHttpRequest ();
$ ('Showallnodes '). onclick = function (){

Xmlhttp. open ('GET', 'node/allnodes. php', true );
Xmlhttp. onreadystatechange = showclass;
Xmlhttp. send (null );
}
Write with jQuery
$ ('# Showallnodes'). click (function (){
$. Get ('node/allnodes. php', showclass );
})

I found the problem, that is, the method is wrong, and the asynchronous method is okay, but how can I display it? I followed the example code of the person-to-person comparison.
Is there a problem with this return method? I used a browser for debugging and found that 200, the asynchronous method call was successful,
But how can it not be displayed,
Function showclass (){
If (xmlhttp. readystate = 4 ){
If (xmlhttp. status = 200 ){
$ ('Showmenu '). innerHTML = xmlhttp. responseText;
}
}
}
This is the id of p in the right sidebar,
Open php page contains this
Header ('content-type: text/html; charset = utf-8 ');
Right? why can't I display it? I can call ie before, but I cannot display it now. the asynchronous method returns 200. it should be okay. how can I display it?
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.