【发布时间】:2014-10-22 11:09:56
【问题描述】:
我正在尝试从 jquery 使用 Web 服务方法,但我在下面收到此错误
Uncaught SyntaxError: Unexpected token
它指向我的服务方法 url。下面是我的代码,
$("#btnDialog").click(function () {
var test = $("#hfID").val();
testService(test);
$("#dialog").dialog("open");
});
function testService(test) {
$.ajax({
crossDomain: true,
type: "POST",
url: "http://localhost:64461/Service1.asmx?op=HelloWorld",
data: test,
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
success: function(json) {
$("#lblID").text(json.responseText);
},
failure: function(response) {
alert("Did not work");
}
});
}
网络服务方式是
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld(string id)
{
string toReturn = null;
if (string.IsNullOrEmpty(id))
{
toReturn = "recieved but nothing";
}
else
{
Class1 class1 = new Class1();
class1.GetName();
toReturn = class1.GetName();
}
return toReturn;
}
}
【问题讨论】:
-
你确定它应该是 jQuery 中的 POST 类型调用吗?
标签: c# jquery asp.net ajax web-services