nav*_*een 1 javascript ajax jquery
我有以下脚本
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;
Run Code Online (Sandbox Code Playgroud)
我知道如何$.ajax在jQuery中编写.但我坚持如何发送数据.
我的问题是
dataType: xml.我对么?请详细说明这些事情.
免责声明:问题是我无法自己测试,所以这个问题.
1返回是XML,因此dataType:xml.我对么?
实际上,如果服务器将正确的Content-Type标头设置为,则需要指定它text/xml.jQuery会自动将结果视为XML
2我应该如何将数据传递给网址?
您可以使用data哈希:
$.ajax({
url: '/getSelectedProductData',
type: 'GET',
dataType: 'xml', // not necessary if the server sets the Content-Type: text/xml response header
data: {
offerCollectionRef: offerCollectionRef,
brandRef: brandRef,
priceRef: priceRef,
defaultSmallImage: defaultSmallImage,
offerCode: offerCode,
index: index
},
success: function(xml) {
// ...
}
});
Run Code Online (Sandbox Code Playgroud)
此外,您似乎通过将async参数设置为false来发送同步请求.要使用jQuery模拟相同的内容,您可以添加该async: false选项.话虽这么说,你可能不应该这样做.SJAX(同步javascript)将在请求期间阻止浏览器并破坏用户体验.
| 归档时间: |
|
| 查看次数: |
77 次 |
| 最近记录: |