您的位置:首页 > Web前端 > JavaScript

js用jsonp跨域问题

2016-01-08 14:26 627 查看
提交button如果用<button>标签提示,不允许跨域

改成<input 就好了..

前段:

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

var name = $("#firstname").val();

var pwd = $("#lastname").val();

$.ajax({

url: "http://localhost:38620/client/ClientLogin?callback=ff",

type: "get",

cache: false,

jsonp: "",//传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(一般默认为:callback)

jsonpCallback: "myCallBack",//自定义的jsonp回调函数名称,默认为jQuery自动生成的随机函数名,也可以写"?",jQuery会自动为你处理数据

crossDomain: true,

data: { name: name, pwd: pwd },

dataType: 'jsonp',

success: function (html) {

alert("html" + html);

},

error: function (code) {

alert("error" + code);

}

});

});

后端:

if (client != null)

{

//need to use

Session["CurrentCustomer"] = client;

retResult.obj = client.AllName;

retResult.success = true;

}

else

{

retResult.obj = "用户名密码错误";

retResult.success = false;

}

string test = new JavaScriptSerializer().Serialize(retResult);

return new ContentResult()

{

Content = string.Format("myCallBack({0})", test),

ContentType = "application/script"

};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: