jquery ajax 跨域请求

使用 jquery 中的ajax  进行跨域请求
说明:dataType 为  "jsonp"  ;type 只能为 GET

前台请求代码
$.ajax({
                type: "GET",
                url: "http://www.xxx.com/Rest/ValidAccountsExists.aspx?accounts=admin",             
                dataType: "jsonp",
                jsonp: "jsoncallback",   
                success: function (result) {    
alert(result.Success);    
alert(result.Content);                                
                },

                error: function (result, status) {
                   //处理错误
                }
            });

后台处理代码 ValidAccountsExists.aspx


string accounts = GameRequest.GetQueryString("accounts");
string jsoncallback = GameRequest.GetQueryString("jsoncallback");
Response.ContentEncoding =System.Text.Encoding.UTF8;
Response.ContentType = "application/json";
Response.Write(jsoncallback + "({\"Success\":\"True\",\"Content\":\"" + accounts  + "\"})");
 Response.End();


posted @ 2013-02-05 19:53  H辉  阅读(1515)  评论(0编辑  收藏  举报