jquery跨域问题!
我创建了一个 post 类型的服务。当我从 jquery ajax 发送数据时,它不起作用。GET 类型的方法工作正常。 我也需要帖子类型。解决方案是什么。请帮忙。
var user = document.getElementById("uname").value;
var pass = document.getElementById("pass").value;
var utyp = document.getElementById("usertyp").value;
// alert("hi"+pass);
var dat = { "uname": user, "pwd": pass, "utype": utyp };
Data = JSON.stringify(dat);
$.ajax({
url: "http://192.168.1.9:450/Service.svc/Login_Insert",
type: "POST",
data:Data,
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
processdata: true,
success: function res(msg) {
alert("hello" + msg);
},
error: function error(response) {
alert("error");
alert(response.responseText);
alert(JSON.stringify(response));
}
});
问候, 吉里布山
i have created a service of type post.When i am sending data from jquery ajax it is not working.Method of type GET working fine.
I need with post type also .what is the solution.Please help.
var user = document.getElementById("uname").value;
var pass = document.getElementById("pass").value;
var utyp = document.getElementById("usertyp").value;
// alert("hi"+pass);
var dat = { "uname": user, "pwd": pass, "utype": utyp };
Data = JSON.stringify(dat);
$.ajax({
url: "http://192.168.1.9:450/Service.svc/Login_Insert",
type: "POST",
data:Data,
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
processdata: true,
success: function res(msg) {
alert("hello" + msg);
},
error: function error(response) {
alert("error");
alert(response.responseText);
alert(JSON.stringify(response));
}
});
Regards,
giri Bhushan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用JSONP解决跨域请求。这实际上是一种绕过浏览器安全模型的黑客攻击。它的工作原理是包含一个远程脚本块并在准备好时自动执行回调函数。这只能通过 GET 请求来完成
cross domain requests are solved using JSONP. This is effectively a hack to work around the browser security model. It works by including a remote script block and auto executing a callback function when ready. This can ONLY be done as a GET request
一些提示:
在这里我修改了您的代码
参考
some TIPS:
here i modified your code
REFERENCE
在您调用的服务方法中,将这 4 行代码插入到下面函数的开头。
另外,在 svc 文件中,在函数之前添加这一行,如下所示。
如果你也需要 web.config,这里是
in your service method you are calling, insert these 4 lines of code in start of the function below.
also, in svc file add this line before your function like in the one below.
if you need web.config too, here it is