I have the following script
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "/getSelectedProductData?offerCollectionRef=" + offerCollectionRef + "&brandRef=" + brandRef + "&priceRef=" + priceRef + "&defaultSmallImage=" + defaultSmallImage + "&offerCode=" + offerCode + "&index=" + index, false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
I know how to write a $.ajax in jQuery. But I am stuck at how to send data.
My questions are
- The return is XML and so the
dataType: xml. am I correct? - How should I pass the data to the url?
Please elaborate on these things.
Disclaimer: The thing is that I couldn’t test it myself and so this question.
You actually don;t need to specify it if the server sets proper Content-Type header to
text/xml. jQuery will automatically consider the result as XMLYou could use the
datahash:Also you seem to be sending a synchronous request by setting the async parameter to false. To emulate the same with jQuery you could add the
async: falseoption. This being said, you probably shouldn’t be doing it. SJAX (sync javascript) will block the browser during the request and ruin the user experience.