尋找一些幫助,使用XMLHttpRequest將以下內容從jquery ajax轉換爲javascript?
$.ajax({
url: 'api/dev/blah?id=4F',
type: 'GET',
beforeSend: function(req) {
req.setRequestHeader("Accept", "application/xml");
},
success: function (result) {
alert('success');
// Parse xml here...
},
error: function() {
alert('error');
}
});
我已經試過類似的東西到這一點,但我無法看到提琴手發送的請求,暗示無響應或錯誤(不XMLHttpRequest的精明):
function junk() {
var request = new XMLHttpRequest();
request.addEventListener('load', successCallback, false);
request.open("GET", 'api/dev/blah?id=4F', true);
request.setRequestHeader("Accept","application/xml");
request.setRequestHeader("Content-Type", "application/xml");
request.send();
}
function successCallback(data) {
alert('success');
}
你能解釋一下你需要什麼特別的幫助?你是否得到錯誤等? – dstarh 2012-07-09 21:26:12