ajax跨域访问

客户端页面

var url =
“http://172.16.91.121:81/FellIn/FellIn.aspx?Action=WXSave&WX_StoreID=”

  • $(“#WX_StoreID”).val() + “&WX_UserID=” + UserID;
            $.ajax(
            {
                type: “get”,
                url: url,
                dataType: ‘jsonp’,
                jsonp:
    “callbackparam”,
                jsonpCallback:
    “callbackparam”,
                success: function (data)
    {
                   
                },
                error: function () {
                    $(“#fi_NO”).val(“查询失败”);
                    $(“#fi_Code”).val(“查询失败”);
                    $(“#fi_WaitingNum”).val(“查询失败”);
                }
            });

function callbackparam(parameters) {
        $(“#fi_NO”).val(parameters[0].fi_NO);
        $(“#fi_Code”).val(parameters[0].fi_Code);
        $(“#fi_WaitingNum”).val(parameters[0].fi_WaitingNum);
    }

 

服务器端:

Response.ContentType = “text/plain”;

var callbackFunName = context.Request[“callbackparam”];
httpContext.Response.Write(callbackFunName +”(“); //callbackFunName
为达到文中的callbackparam

httpContext.Response.Write(Data);          //Data 是服务器返回的数码   就是json格式     

httpContext.Response.Write(“);”);        //记得括号

 

健康同源ajax:

$.ajax({
            url:
‘Store_Info.ashx’,
            type: “GET”,
            traditional: true,
            success: function (date)
{
                returnData =
$.parseJSON(date);
                set();
            }
        });

相关文章

网站地图xml地图