您的位置:首页 > 其它

AJAX的跨域访问-两种有效的解决方法介绍

2013-06-22 15:00 726 查看

/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
    try {
  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e2) {
  xmlHttp = false;
    }
}
@end @*/
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
     xmlHttp = new XMLHttpRequest();
}
var url = "http://127.0.0.1:2012/esb/servlet/HttpClient?randomType=MIX";
xmlHttp.open("GET", url, true);
//Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = function(){
    if (xmlHttp.readyState == 4) {
  var response = xmlHttp.responseText;
  alert(response);
}
}
//Send the request
xmlHttp.send(null);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  AJAX 跨域访问