如何将参数传递给 XMLHttpRequest 对象?
function setGUID(aGUID) {
var xhReq = new XMLHttpRequest();
xhReq.open("POST", "ClientService.svc/REST/SetAGUID" , false);
xhReq.send(null);
var serverResponse = JSON.parse(xhReq.responseText);
alert(serverResponse);
return serverResponse;
}
我需要使用 javascript 而不是 jquery,在 jquery 中我可以使用此代码,但似乎无法弄清楚直接的 javascript 方式..
function setGUID(aGUID) {
var applicationData = null;
$.ajax({
type: "POST",
url: "ClientService.svc/REST/SetAGUID",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ aGUID: aGUID }),
dataType: "json",
async: false,
success: function (msg) {
applicationData = msg;
},
error: function (xhr, status, error) { ); }
});
return applicationData;
}