无效的JSON数据$ .get()方法 - 未捕获的语法错误:意外的令牌< [英] Invalid JSON data $.get() method - uncaught syntaxerror: unexpected token <

查看:58
本文介绍了无效的JSON数据$ .get()方法 - 未捕获的语法错误:意外的令牌<的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助的人。



我正在尝试从返回JSON数据的服务器获取数据但是我收到以下错误消息(在Firefox 48中) )。





未捕获的SyntaxError:意外的令牌& lt;



似乎返回的JSON数据无效或者不是预期的格式。



当我在Chrome 52中运行它时,没有错误消息和数据是在响应中返回的,但它不会在我的函数中运行代码。



我的服务器以下面的JSON格式返回数据。



 [{  ActionCardId 1   ActionCardNumber  279877 < span class =code- string> AccountNo:  2202322179  ClientName null    CellNumber  0787596971  TenantName null   TenantCellNumber null   AddressStandNo null   AddressStreet  43 DELMAS AVENUE  AddressSuburb   BOKSBURG  AddressCity null   AddressPortion null   AddressEarthNo null   AddressPremise null   AddressGISKEY null   AmountDueTotal 4080  0   AmountDue30Day null   AmountDueCurrent null   AmountDue60Day null    ServiceLevy null   MeterNumberWater null   MeterNumberElectricity  M22541  MeterNumberElectricity2 null   MeterNumberElectricity3 null   MeterNumberPrePaid null   IsPrinted:< span class =code-keyword> true ,  IsResidential null   ActionSuccessful false   ActionCardDate  2016-08-22T00:00:00 备注 null   UnSuccessfulReason null   CaptureContractorId null   AddressCombo ,43 DELMAS AVENUE,BOKSBURG ,, / span>,  BillCycleName  120  ServiceIndicator null   WaterReading null   WaterReadingDate null   ElectricityReading null   ElectricityReadingDate null  单位: null   ActionCardTypeId 2   ContractorId:< span class =code-digit> 1   ActionCardStatusId 1   UnSuccessfulActionReasonId null   TechnicianId 1   AccountInfoId null   ServiceDeliveryCentreId 4   BillCycleId 2   ActionCardType null  承包商 null   ActionCardStatus null   UnSuccessfulActionReason null  技术人员 null   AccountInfo null   ServiceDeliveryCentre null   BillCycle null   ActionName  ED  DateCreated   2016-07-06T00:00:00  DateModified  2016-08-13T10:24:17.5833635  CreatedByOnlineUserId:< span class =code-keyword> null   ModifiedByOnlineUserId  fa93e65d-e4a7-4a0c-91c6-4561e2612f9c  CreatedByUser null   ModifiedByUser null },{  ActionCardId 2    ActionCardNumber  279876  AccountNo  2200630592  ClientName:< span class =code-keyword> null ,  CellNumber  0787596971  TenantName null   TenantCellNumber null   AddressStandNo  null   AddressStreet  43 DELMAS AVENUE  AddressSuburb  BOKSBURG  AddressCity null   AddressPortion null   AddressEarthNo null   AddressPremise null   AddressGISKEY null   AmountDueTotal 4080  0   AmountDue30Day null   AmountDueCurrent:< span class =code-keyword> null ,  AmountDue60Day null   ServiceLevy null   MeterNumberWater null   MeterNumberElectricity:  M22541  MeterNumberElectricity2 null   MeterNumberElectricity3 null   MeterNumberPrePaid null   IsPrinted true   IsResidential null   ActionSuccessful false   ActionCardDate   2016-08-22T 00:00:00 备注 null   UnSuccessfulReason null   CaptureContractorId null   AddressCombo ,43 DELMAS AVENUE,BOKSBURG,  BillCycleName  120   ServiceIndicator null   WaterReading null   WaterReadingDate null   ElectricityReading null    ElectricityReadingDate null  单位 null   ActionCardTypeId 2   ContractorId 1   ActionCardStatusId 1   UnSuccessfulActionReasonId null   TechnicianId 1   AccountInfoId null    ServiceDeliveryCentreId 4   BillCycleId 2   ActionCardType null  承包商 null   ActionCardStatus null   UnSuccessfulActionReason null  < span class =code-string>技术人员 null   AccountInfo null   ServiceDeliveryCentre null   BillCycle null   ActionName  ED   DateCreated  2016-07 -06T00:00:00  DateModified  2016-08-13T10:51:16.575637 <跨越式s =code-string> CreatedByOnlineUserId: null   ModifiedByOnlineUserId  fa93e65d-e4a7-4a0c-91c6-4561e2612f9c  CreatedByUser null   ModifiedByUser null }, {  ActionCardId 3 ,< span class =code-string>  ActionCardNumber  279875  AccountNo  2200630306   ClientName null   CellNumber  0787596971  TenantName null   TenantCellNumber null   AddressStandNo null   AddressStreet  43 DELMAS AVENUE  AddressSuburb  BOKSBURG  AddressCity null   AddressPortion null   AddressEarthNo null   AddressPremise null   AddressGISKEY  null   AmountDueTotal 4080  0   AmountDue30Day null   AmountDueCurrent null   AmountDue60Day null    ServiceLevy null   MeterNumberWater null   MeterNumberElectricity  M22541  MeterNumberElectricity2 null   MeterNumberElectricity3 null   MeterNumberPrePaid null   IsPrinted true   IsResidential null   ActionSuccessful true   ActionCardDate   2016-08-22T00:00:00 备注 null   UnSuccessfulReason null   CaptureContractorId null   AddressCombo  ,43 DELMAS AVENUE,BOKSBURG ,, / span>,  BillCycleName  120  ServiceIndicator null   WaterReading null   WaterReadingDate null   ElectricityReading null   ElectricityReadingDate null  单位 null   ActionCardTypeId 2   ContractorId 1   ActionCardStatusId 1   UnSuccessfulActionReasonId null   TechnicianId 1   AccountInfoId null   ServiceDeliveryCentreId 4   BillCycleId 2   ActionCardType null  承包商 null   ActionCardStatus null   UnSuccessfulActionReason null  技术人员 null   AccountInfo null ,< span class =code-string>  ServiceDeliveryCentre null   BillCycle null   ActionName  ED  DateCreated  2016-07-06T00:00:00  DateModified  2016- 08-13T10:51:16.6757162  CreatedByOnlineUserId null   ModifiedByOnlineUserId  fa93e65d-e4a7-4a0c-91c6-4561e2612f9c  CreatedByUser null   ModifiedByUser null }] 





Wha这可能是问题吗?



我正在使用jsonp,因为我使用跨域。

谢谢。



我尝试了什么:



 $(< span class =code-string>  #importDailyJobs)。click( function  (){

var technicianId = 1 ;

var serverUrl = http:// localhost:35825 / Mobile / ImportDailyReadings

$ .get(serverUrl,{TechnicianId:technicianId}, function (数据,状态){

alert( 成功);
console .log(data);


}, jsonp);

});

解决方案

#importDailyJobs)。click( function (){

var technicianId = 1 ;

var serverUrl = http:// localhost:35825 / Mobile / ImportDailyReadings

.get(serverUrl,{TechnicianId:technicianId}, function (数据,状态){

alert( 成功);
console .log(data);


}, jsonp);

});


错误在于你的ajax请求,你的ajax请求中没有提到你要回复的数据类型。我想如果你提出下面这个请求的请求,你的错误就会得到解决。



 


I need help guys.

I am trying to fetch data from the server which is returning JSON data but I am getting the following error message (in Firefox 48).


Uncaught SyntaxError: Unexpected token &lt;

It seems like the JSON data that is returned is invalid or its not in the expected format.

When I run it in Chrome 52, there is no error message and the data is being returned on the response but it does not run the code inside my function.

My server is returning data in the following JSON format.

[{ "ActionCardId": 1, "ActionCardNumber": "279877", "AccountNo": "2202322179", "ClientName": null, "CellNumber": "0787596971", "TenantName": null, "TenantCellNumber": null, "AddressStandNo": null, "AddressStreet": "43 DELMAS AVENUE", "AddressSuburb": "BOKSBURG", "AddressCity": null, "AddressPortion": null, "AddressEarthNo": null, "AddressPremise": null, "AddressGISKEY": null, "AmountDueTotal": 4080.0, "AmountDue30Day": null, "AmountDueCurrent": null, "AmountDue60Day": null, "ServiceLevy": null, "MeterNumberWater": null, "MeterNumberElectricity": "M22541", "MeterNumberElectricity2": null, "MeterNumberElectricity3": null, "MeterNumberPrePaid": null, "IsPrinted": true, "IsResidential": null, "ActionSuccessful": false, "ActionCardDate": "2016-08-22T00:00:00", "Remarks": null, "UnSuccessfulReason": null, "CaptureContractorId": null, "AddressCombo": ", 43 DELMAS AVENUE, BOKSBURG, , ", "BillCycleName": "120", "ServiceIndicator": null, "WaterReading": null, "WaterReadingDate": null, "ElectricityReading": null, "ElectricityReadingDate": null, "Unit": null, "ActionCardTypeId": 2, "ContractorId": 1, "ActionCardStatusId": 1, "UnSuccessfulActionReasonId": null, "TechnicianId": 1, "AccountInfoId": null, "ServiceDeliveryCentreId": 4, "BillCycleId": 2, "ActionCardType": null, "Contractor": null, "ActionCardStatus": null, "UnSuccessfulActionReason": null, "Technician": null, "AccountInfo": null, "ServiceDeliveryCentre": null, "BillCycle": null, "ActionName": "ED", "DateCreated": "2016-07-06T00:00:00", "DateModified": "2016-08-13T10:24:17.5833635", "CreatedByOnlineUserId": null, "ModifiedByOnlineUserId": "fa93e65d-e4a7-4a0c-91c6-4561e2612f9c", "CreatedByUser": null, "ModifiedByUser": null }, { "ActionCardId": 2, "ActionCardNumber": "279876", "AccountNo": "2200630592", "ClientName": null, "CellNumber": "0787596971", "TenantName": null, "TenantCellNumber": null, "AddressStandNo": null, "AddressStreet": "43 DELMAS AVENUE", "AddressSuburb": "BOKSBURG", "AddressCity": null, "AddressPortion": null, "AddressEarthNo": null, "AddressPremise": null, "AddressGISKEY": null, "AmountDueTotal": 4080.0, "AmountDue30Day": null, "AmountDueCurrent": null, "AmountDue60Day": null, "ServiceLevy": null, "MeterNumberWater": null, "MeterNumberElectricity": "M22541", "MeterNumberElectricity2": null, "MeterNumberElectricity3": null, "MeterNumberPrePaid": null, "IsPrinted": true, "IsResidential": null, "ActionSuccessful": false, "ActionCardDate": "2016-08-22T00:00:00", "Remarks": null, "UnSuccessfulReason": null, "CaptureContractorId": null, "AddressCombo": ", 43 DELMAS AVENUE, BOKSBURG, , ", "BillCycleName": "120", "ServiceIndicator": null, "WaterReading": null, "WaterReadingDate": null, "ElectricityReading": null, "ElectricityReadingDate": null, "Unit": null, "ActionCardTypeId": 2, "ContractorId": 1, "ActionCardStatusId": 1, "UnSuccessfulActionReasonId": null, "TechnicianId": 1, "AccountInfoId": null, "ServiceDeliveryCentreId": 4, "BillCycleId": 2, "ActionCardType": null, "Contractor": null, "ActionCardStatus": null, "UnSuccessfulActionReason": null, "Technician": null, "AccountInfo": null, "ServiceDeliveryCentre": null, "BillCycle": null, "ActionName": "ED", "DateCreated": "2016-07-06T00:00:00", "DateModified": "2016-08-13T10:51:16.575637", "CreatedByOnlineUserId": null, "ModifiedByOnlineUserId": "fa93e65d-e4a7-4a0c-91c6-4561e2612f9c", "CreatedByUser": null, "ModifiedByUser": null }, { "ActionCardId": 3, "ActionCardNumber": "279875", "AccountNo": "2200630306", "ClientName": null, "CellNumber": "0787596971", "TenantName": null, "TenantCellNumber": null, "AddressStandNo": null, "AddressStreet": "43 DELMAS AVENUE", "AddressSuburb": "BOKSBURG", "AddressCity": null, "AddressPortion": null, "AddressEarthNo": null, "AddressPremise": null, "AddressGISKEY": null, "AmountDueTotal": 4080.0, "AmountDue30Day": null, "AmountDueCurrent": null, "AmountDue60Day": null, "ServiceLevy": null, "MeterNumberWater": null, "MeterNumberElectricity": "M22541", "MeterNumberElectricity2": null, "MeterNumberElectricity3": null, "MeterNumberPrePaid": null, "IsPrinted": true, "IsResidential": null, "ActionSuccessful": true, "ActionCardDate": "2016-08-22T00:00:00", "Remarks": null, "UnSuccessfulReason": null, "CaptureContractorId": null, "AddressCombo": ", 43 DELMAS AVENUE, BOKSBURG, , ", "BillCycleName": "120", "ServiceIndicator": null, "WaterReading": null, "WaterReadingDate": null, "ElectricityReading": null, "ElectricityReadingDate": null, "Unit": null, "ActionCardTypeId": 2, "ContractorId": 1, "ActionCardStatusId": 1, "UnSuccessfulActionReasonId": null, "TechnicianId": 1, "AccountInfoId": null, "ServiceDeliveryCentreId": 4, "BillCycleId": 2, "ActionCardType": null, "Contractor": null, "ActionCardStatus": null, "UnSuccessfulActionReason": null, "Technician": null, "AccountInfo": null, "ServiceDeliveryCentre": null, "BillCycle": null, "ActionName": "ED", "DateCreated": "2016-07-06T00:00:00", "DateModified": "2016-08-13T10:51:16.6757162", "CreatedByOnlineUserId": null, "ModifiedByOnlineUserId": "fa93e65d-e4a7-4a0c-91c6-4561e2612f9c", "CreatedByUser": null, "ModifiedByUser": null }]



What could be the issue here?

I am using jsonp because I am using cross domain.
Thank you.

What I have tried:

$("#importDailyJobs").click(function () {

        var technicianId = 1;

        var serverUrl = "http://localhost:35825/Mobile/ImportDailyReadings"

        $.get(serverUrl, { TechnicianId: technicianId }, function (data, status) {

            alert("Success");
            console.log(data);


        }, "jsonp");

    });

解决方案

("#importDailyJobs").click(function () { var technicianId = 1; var serverUrl = "http://localhost:35825/Mobile/ImportDailyReadings"


.get(serverUrl, { TechnicianId: technicianId }, function (data, status) { alert("Success"); console.log(data); }, "jsonp"); });


Error is in your ajax request, you are not mentioned in your ajax request which type of data you are getting in response. I Think if you make request like this request mention below, your error will be resolved.


这篇关于无效的JSON数据$ .get()方法 - 未捕获的语法错误:意外的令牌&lt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆