【发布时间】:2011-08-01 14:57:38
【问题描述】:
我在我的网站中编写了以下 webservice asmx 文件:
[WebService(Namespace = "http://eumcore.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class jsonTest : System.Web.Services.WebService {
public jsonTest () {
}
[WebMethod(Description = "Gets the names matching part of a title.")]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void getName() {
List<nameEntry> nameList = new List<nameEntry>();
nameList.Add(new nameEntry() {id="1", name="John"});
nameList.Add(new nameEntry() { id = "3", name = "Alex" });
this.Context.Response.ContentType = "application/json; charset=utf-8";
JavaScriptSerializer js = new JavaScriptSerializer();
string strJSON = js.Serialize(nameList);
this.Context.Response.Write(strJSON);
}
}
一开始我希望它每次都返回相同的数组,当我直接调用它时,webservice的结果是:
[{"id":"1","name":"John"},{"id":"3","name":"Alex"}]
哪个是正确的回复,当我将它用作本地输入时,结果很好,但是当我在 tokeninput 的输入法中调用 web 服务时(我为函数分配了一条错误消息),我收到以下错误:“ 200 解析器错误未定义”
谁能帮我弄清楚?
谢谢
多伦
编辑:在玩弄了一下 jquery 代码后,我设法接收到数据,但出现以下错误:
200
解析器错误
[{"id":"1","name":"aaA"},{"id":"3","name":"aaA"}]{"d":null}
我不明白的是 d 是什么,为什么它是 null?
【问题讨论】:
-
when i call the webservice in the input method of tokeninput是什么意思? -
从运行 jquery 的 html 中:
-
您尝试从中调用此 Web 服务的网页是否也托管在 localhost:61965 上,还是位于单独的应用程序中?
-
它不是应用程序的一部分,但文件本身在机器上。它到达目的地是因为我的代码中有断点并且它停止了
-
您似乎正在尝试执行不允许的跨域 AJAX 请求。同源策略规定您必须仅将 AJAX 请求发送到同一个域。确保这一点的最佳方法是永远不要使用绝对网址,而只使用相对网址,例如:
$("#demo-input").tokenInput("/names/jsonTest.asmx/getName");
标签: jquery asp.net json jquery-plugins