我使用以下代码在Internet Explorer中执行跨域操作。
if (window.XDomainRequest) { // Check whether the browser supports XDR.
xdr = new XDomainRequest(); // Create a new XDR object.
if (xdr) {
// There is an error and the request cannot be completed.
// For example, the network is not available.
xdr.onerror = alert_error;
// This event is raised when the request reaches its timeout.
xdr.ontimeout = alert_timeout;
obj['username'] = username;
obj['password'] = password;
// When the object starts returning data, the onprogress event
// is raised and the data can be retrieved by using responseText.
xdr.onprogress = alert_progress;
// When the object is complete, the onload event is raised and
// the responseText ensures the data is available.
xdr.onload = alert_loaded;
xdr.timeout = 5000;
// The URL is preset in the text area. This is passed in the
// open call with a get request.
xdr.open("post", action);
}
// The request is then sent to the server.
xdr.send(JSON.stringify(obj));
}
数据保存在JSON对象中,该对象在作为XDomainRequest
的一部分发送之前进行了字符串化。
但不知怎的JSON.stringify(obj)
正在发送空值。