<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=uft-8" />
<script src="jquery.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function Search1() {
$.post('http://####/123.svc/222222/UserId=@@@',{}, function (data,statu) {
alert(data);
if (statu == 'success') {
alert(data);
}
});
}
function Search2() {
$.post('http://#####/222222.ashx', { "rrrrrr":'@@@' }, function (data,statu) {
if (statu == 'success') {
alert(data);
if(data=="false"){
alert("请登录后再进行此操作");
}
else{
alert(123);
}
}
})
}
function Search3() {
$.ajax({
async:false,
url: 'http://####/123.svc/22222/UserId=@@@', // 跨域URL
type: 'GET',
dataType: 'jsonp',
jsonp: 'jsoncallback', //默认callback
timeout: 5000,
beforeSend: function(){ //jsonp 方式此方法不被触发。原因可能是dataType如果指定为jsonp的话,就已经不是ajax事件了
},
success: function (json) { //客户端jquery预先定义好的callback函数,成功获取跨域服务器上的json数据后,会动态执行这个callback函数
if(json.actionErrors.length!=0){
alert(json.actionErrors);
}
// genDynamicContent(qsData,type,json);
alert(json[0].value);
},
error: function(xhr){
//jsonp 方式此方法不被触发
//请求出错处理
alert("请求出错(请检查相关度网络状况.)");
}
});
}
function Search4()
{var result = "";
var xhr = new XMLHttpRequest();
xhr.open("get", 'http://####/2222.ashx?rrrrr=@@@', true);
xhr.setRequestHeader("If-Modified-Since", "0");
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
result = xhr.responseText;
alert(result);
}
};
xhr.send(null);
}
function Search5()
{
$.ajax({
type : "get",
url : "http://####/22222.ashx?rrrrr=@@@",
dataType : "jsonp",
jsonp: "jsoncallback",
success : function(msg) {
if(msg){
alert(msg[0].value);
}
}
});
}
function Search6()
{
$.getJSON("http://####/22222.ashx?rrrrr=@@@", {}, function(response)
{
debugger;
alert(response);
});
}
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<input type=button value="1" οnclick=Search1()>
<input type=button value="2" οnclick=Search2()>
<input type=button value="3" οnclick=Search3()>
<input type=button value="4" οnclick=Search4()>
<input type=button value="5" οnclick=Search5()> <input type=button value="6" οnclick=Search6()>
<div id="msg">
</div>
</form>
</body>
</html>
==========================后台只能这样搞,WCF的貌似不好使
if (context.Request["jsoncallback"] != null)
{
string jsoncall = context.Request["jsoncallback"].ToString();
//封装JSon格式
sb.Append(jsoncall + "([{\"value\":\"");
sb.Append(pk);
sb.Append("\"}])");
}