简体   繁体   English

jQuery Ajax,缺少; 声明前

[英]Jquery Ajax, missing ; before statement

I have a jquery ajax call that is making a cross-domain request. 我有一个跨域请求的jquery ajax调用。 all the js syntax looks good, and the response looks good, but i keep getting the "missing ; before statement error" in firebug (console). 所有的js语法看起来都不错,响应看起来也不错,但是我在萤火虫(控制台)中不断收到“ missing; before statement error”。 Here's my web service: 这是我的网络服务:

[WebMethod()]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, XmlSerializeString = false, UseHttpGet = true)]
public string HelloToYou(string name)
{
    return "Hello " + name;
}

here's my javascript: 这是我的JavaScript:

function HelloToYou() {
    $.getJSON(
        "http://localhost/test/webservicedemo.asmx/HelloToYou?callback=?",
        { name : "nathan" },
        function() { alert("something"); }
    );
}

any ideas? 有任何想法吗?

Your code looks like it's retrieving jsonp data? 您的代码看起来像是在检索jsonp数据? If my assumption is correct it might be that the json is invalid and causing the error. 如果我的假设正确,则可能是json无效并导致错误。

I'm not an interpreter but your javascript code looks ok. 我不是口译员,但您的JavaScript代码看起来不错。 If you have access to the json that is retrieved try making it something simple eg [] 如果您有权访问检索到的json,请尝试使其变得简单一些,例如[]

您确定已正确导入jquery .js文件吗?

I think in your js function missing parameter.. Try this 我认为您的js函数缺少参数。

function HelloToYou() {
    $.getJSON(
        "http://localhost/test/webservicedemo.asmx/HelloToYou?callback=?",
        { name : "nathan" },
        function(data) { alert("something"); }
    );
}

Very probably the JSON data, which is eval'ed upon being received. 很有可能是JSON数据,该数据在收到后即被评估。 The eval() is most likely throwing this error. eval()最有可能引发此错误。 Check the data via jsonlint.com. 通过jsonlint.com检查数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM