XMLHttpRequest in Ajax and PHP
In internet explorer we can create the object of ActiveXObject like follows
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loa开发者_开发百科d("note_error.xml");
It is possible to use the xmlDoc.load("note_error.xml"); for the object of XMLHttpRequest in other browsers.If no,any other substitute for this method when we use XMLHttpRequest.Please help...am using firefox as my browser
xmlDoc.async="false";
That's not doing what you think. async
is a boolean property. When you assign the string "false"
to it, you're getting the value true
, because all non-empty strings are truthy.
It is possible to use the xmlDoc.load("note_error.xml"); for the object of XMLHttpRequest in other browsers.
Yes, in fact that's what you should be doing in IE too. There is no reason to use XMLDOM
to fetch an XML Document; XMLHttpRequest can do that fine and it's much more widely supported.
var xhr= window.XMLHttpRequest? new XMLHttpRequest() : new ActiveXObject('MSXML2.XMLHttp');
xhr.async= false;
xhr.open('GET', 'note_error.xml');
xhr.send();
var doc= xhr.responseXML;
If you do need an XMLDOM
-like object in other browsers, it's called new DOMParser
, but it's not as widely-supported as XMLHttpRequest
.
the activeX 'concept' is only in Internet Explorer. All other browser implement a similar, but more or less standard version.
http://www.w3schools.com/Ajax/ajax_browsers.asp
that shows you how to create an xmlhttp object in 'any' browser.
精彩评论