JQUERY 1.5
function loadPostQry(str) {
$.get( 'fillpage.php','prodcode='+str, function(data) {
$('#s_content').html(data);
},
"html" );
}
this piece of code is running on every browser but not on IE. I think there's something missing, the XHR or something else that has got to do with the engine.
//Dont get confused with this one, The above code is what I'm trying to get some answers...
JQUERY 1.4
function getXMLHttpRequest()
{
if (window.XMLHttpRequest) {
return new window.XMLHttpRequest;
}
else {
try {
return new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
catch(ex) {
return null;
}
}
}
I am trying to accomplished like the ver1.4 code...
Q: How would I write that piece of code to be compatible to ver1.5, everytime that code is called it will first check the engine.
This is an exerpt from JQUERY site...
--xhr--- Default: ActiveXObject when available (IE), the XMLHttpRequest otherwise Callback for creating the XMLHttpRequest object. Defaults to the ActiveXObject when available (IE), the XMLHttpRequest otherwise. Override to provide your own implementation for XMLHttp开发者_StackOverflow社区Request or enhancements to the factory
Need a work around.. Thanks...
I too am having a difficult time understanding your question, but I think you are asking how to access the native XHR object in the same way you did in versions previous to 1.5. If your question is how to check whether the browser supports XMLHTTPRequest, you shouldn't have to do that; that's the whole point of using jQuery.
The ajax method in jQuery 1.5 returns a jqXHR object, which is an augmented version of the native browser XHR object that was returned in earlier versions. This object is a superset of the native browser XHR object, so all methods and properties of the original are inherited. If you want access to the jqXHR object, the following code will work. I have created a jsfiddle http://jsfiddle.net/parkerault/YmdQJ/, and can confirm that it works in IE7 and IE8.
var loadPostQry = function(str) {
return $.ajax({
type: 'GET',
url: '/fillpage.php',
cache: false,
data: {
prodcode: str
}
});
};
var complete = function(jqXHR, status) {
document.write('returned: ' + jqXHR.responseText + '\nwith status: ' + status);
};
var jqxhr = loadPostQry('pancake');
jqxhr.complete(complete);
Any properties that you were able to access from the browser XHR object before 1.5 will still be accessible from jqxhr.
精彩评论