一个修改http header,用jquery访问异域数据的例程

来源:互联网 发布:富士施乐网络打印设置 编辑:程序博客网 时间:2024/04/30 21:38

 

 

<html>

<head>

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>

<script type="text/javascript">

$(document).ready(function(){

$("#b01").click(function(){

 

htmlobj = $.ajax({type:"GET", url:"http://xxxx/handset/handsetapi?catalogId=1", dataType:"xml", timeout:3000, cache:true,

beforeSend:function (XMLHttpRequest) {

alert(XMLHttpRequest.readyState);

 

XMLHttpRequest.setRequestHeader("Client-Agent", "xxxx");

XMLHttpRequest.setRequestHeader("Cookie", "xxxx");

XMLHttpRequest.setRequestHeader("Action", "getxxxxe");

//XMLHttpRequest.setRequestHeader("user-id", "");

//XMLHttpRequest.setRequestHeader("Content-Type", "application/xml");

XMLHttpRequest.setRequestHeader("APIVersion", "1.0.0");

XMLHttpRequest.setRequestHeader("x-up-calling-line-id", "xxxx");

},

success:function (data, textStatus) {

alert("X: 1");

}

});

 

$("#myDiv").html(htmlobj.responseText);

});

});

</script>

</head>

<body>

 

<div id="myDiv"><h2>Let XXX AJAX change this text</h2></div>

<button id="b01" type="button">Change Content</button>

 

</body>

</html>

以上在IE8和android webview, maxthon 1.6.5上测试通过,但在chrom一直http type直接变为OPTION.

 

 

原创粉丝点击