使用Jquery从其他域调用ASMX Web Service
我在一个Visual Studio项目中有一个非常简单的asmx webservice
Hi,
I have a very simple asmx webservice in one Visual Studio project
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string HelloWorld()
{
return "helloworld";
}
}
我试图从Visual中的另一个项目调用此Web服务工作室使用ajax调用
I am trying to call this web service from another project in Visual Studio using ajax call
$(document).ready(function () {
$.ajax({
url: "http://localhost:17889/Service1.asmx/HelloWorld",
type: "POST",
dataType: "jsonp",
crossDomain:true,
contentType: "application/json;charset=utf-8",
success: function (d) {
alert("success");
alert(d.data);
},
error: function (xhr, status, error) {
console.log(xhr.responseText);
console.log(status);
console.log(error);
}
});
});
我的web.config看起来像这样
my web.config looks like this
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://localhost:17889" />
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
</customHeaders>
</httpProtocol>
错误是
未捕获的SyntaxError:意外的令牌<< br mode =hold/>
the errors are
Uncaught SyntaxError: Unexpected token <<br mode="hold" />
undefined
parsererror
错误:jQuery19004053758140653372_1453581966937未被调用(...)
我的方法出了什么问题?我已经经历了很多帖子,但仍然在努力寻找合适的解决方案。
请建议。
parsererror
Error: jQuery19004053758140653372_1453581966937 was not called(…)
what's wrong with my approach? I have gone through a lot of posts, but still struggling to get a proper solution.
Please suggest.
( document )。ready( function (){
(document).ready(function () {
.ajax({
url: http:// localhost:17889 / Service1.asmx / HelloWorld,
类型: POST,
dataType: jsonp,
crossDomain: true ,
contentType: application / json; charset = utf-8,
成功: function (d){
alert( success);
警报(d.data);
},
错误: function (xhr,status,error){
console .log(xhr.responseText);
console .log(status);
console .log(错误);
}
});
});
.ajax({ url: "http://localhost:17889/Service1.asmx/HelloWorld", type: "POST", dataType: "jsonp", crossDomain:true, contentType: "application/json;charset=utf-8", success: function (d) { alert("success"); alert(d.data); }, error: function (xhr, status, error) { console.log(xhr.responseText); console.log(status); console.log(error); } }); });
我的web.config看起来像这样
my web.config looks like this
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://localhost:17889" />
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
</customHeaders>
</httpProtocol>
错误是
未捕获的SyntaxError:意外的令牌<< br mode =hold/>
the errors are
Uncaught SyntaxError: Unexpected token <<br mode="hold" />
undefined
parsererror
错误:jQuery19004053758140653372_1453581966937未被调用(...)
我的方法出了什么问题?我已经经历了很多帖子,但仍然在努力寻找合适的解决方案。
请建议。
parsererror
Error: jQuery19004053758140653372_1453581966937 was not called(…)
what's wrong with my approach? I have gone through a lot of posts, but still struggling to get a proper solution.
Please suggest.