jquery Ajax Request SyntaxError:意外的令牌<

我试图使用get请求返回一系列产品。 响应返回带有200请求的XML。

网络服务:

[WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public List GetAllProducts() { using (SchulteDesignYourOwnEntities db = new SchulteDesignYourOwnEntities()) { return db.products.ToList(); } } 

这是我的代码:

       $(document).ready(function () { $.ajax({ url: 'http://www.organizeliving.com/designwebservice.asmx/GetAllProducts', dataType: 'json', success: function (result) { alert("Result: " + result.length); }, error: function (xhr, ajaxOptions, thrownError) { console.log("Status: " + xhr.status); console.log("Message: " + thrownError); } }); });     

您将dataType'json' 。 jQuery将自动尝试从响应中解析JSON。 如果不能,则认为是错误。

XML是无效的JSON(它真的很讨厌开放< )。 您可以将dataType更改为'xml' (或者不执行任何操作),或者实际从服务器发出纯JSON。