Tag: parse error

WCF 4,JSONP和jQuery导致parsererror

我已经尝试了几乎所有我能想到的东西,但是我仍然遇到了对我的ajax调用WCF服务的问题。 我的WCF服务有如下方法: //[WebInvoke(ResponseFormat = WebMessageFormat.Json, Method = “POST”)] [WebGet] public string Test(int value) { return string.Format(“You entered: {0}”, value); } 正如Patrick Thomas在Twitter上所提到的,我也尝试过使用[WebGet(BodyStyle = WebMessageBodyStyle.Wrapped)]和[WebGet(BodyStyle = WebMessageBodyStyle.WrappedResponse)]而没有运气。 和配置如下: 该服务位于不同的域,所以我将我的数据格式化为JSONP: $.ajax({ cache: false, async: true, type: “GET”, // Was “POST” dataType: “jsonp”, url: “http://mydomain.com/TestService.svc/Test?callback=?”, data: dataToPost, contentType: “application/json;charset=utf-8”, success: function (msg) { var testMsg = JSON.parse(msg); var […]

jQuery AJAX – 意外的令牌+ parsererror

我今天用jQuery和AJAX编写了一个脚本,我收到了一些错误…… 剧本: function changeAdmin(id) { $(document).ready(function() { $(‘#ta-modarea-‘+id).fadeOut(‘fast’); $(‘#ta-m-loading-‘+id).fadeIn(‘fast’); $.ajax({ type: ‘POST’, url: ‘ajax_utf.php?a=changeteamadmin’, dataType: ‘json’, data: { admin : $(‘#admin-id-‘+id).val() }, success: function(data) { $(‘#ta-m-loading-‘+id).fadeOut(‘fast’); $(‘#ta-modarea-‘+id).text(data.msg).fadeIn(‘fast’); }, error: function(jqXHR, textStatus, errorThrown) { $(‘#ta-m-loading-‘+id).fadeOut(‘fast’); $(‘#ta-modarea-‘+id).text(‘HTTP Error: ‘+errorThrown+’ | Error Message: ‘+textStatus).fadeIn(‘fast’); } }); return false; }); } 运行后,我收到此错误消息: HTTP Error: SyntaxError: Unexpected token < | […]

json_encode创建格式错误的JSON(带有额外的隐藏字符)

我正在使用PHP的json_encode()返回一些数据,由jQuery的ajax()检索: 简化的JS: $.ajax({ dataType: ‘json’, contentType: ‘application/json’, cache: false, type: ‘POST’, url: ‘./api/_imgdown.php’, error: function(jqXHR, textStatus, errorThrow) { console.log(jqXHR, textStatus, errorThrow); }, success: function(data, textStatus, jqXHR) { console.log(data, textStatus, jqXHR); } }); PHP是: header(‘Content-Type: application/json; charset=UTF-8’); //default apiResponse $apiResponse = [ “status” => 1, “message” => “success”, “data” => null ]; 然后当php运行我的代码时,它会通过添加这些数据结束: $apiResponse[‘data’][] = [ […]

jQuery.ajax()parsererror

当我尝试从http://api-v3.deezer.com/1.0/search/album/?q=beethoven&index=2&nb_items=2&output=json获取JSON时: (jQuery 1.6.2) $.ajax({ type: “GET”, url: url, dataType: “jsonp”, success: function (result) { alert(“SUCCESS!!!”); }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.statusText); alert(xhr.responseText); alert(xhr.status); alert(thrownError); } }); 我得到: parsererror; 200; undefined; jquery162******************** was not called parsererror; 200; undefined; jquery162******************** was not called 但是使用http://search.twitter.com/search.json?q=beethoven&callback=?&count=5中的JSON工作正常。 两者都是有效的JSON格式。 那么这个错误是什么? [UPDATE] @ 3ngima,我在asp.net中实现了这个,它运行正常: $.ajax({ type: “POST”, url: “WebService.asmx/GetTestData”, data: […]