Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON.parse is not working on iPad safari

I am doing one ajax call and in success function I am using JSON.Parse function.But the problem is that JSON.parse function is working everywhere except in iPad-Safari Browser(iPad Version~7.0.6).In iPad Safari , my code after the line where I used JSON.Parse does not seems to be executed .I tried alert with some message under the line JSON.Parse but had no luck.Can we find a work around of this problem?

Thanks in advance.

Here is the SCRIPT I am running:

var obj = JSON.parse($('#divWOListForFE').html());
alert('hello'); //this alert doesnt execute on iPadSafari
$('#divWOListForFE').html('');
BindWorkOrderGrid(obj, 1, 10);

The value of $('#divWOListForFE').html() is below

"[{"Pk_WorkOrderId":6806,"Fk_CompanyId":null,"Fk_CreatedByUserId":null,"Fk_ProposalId":null,"Fk_InvoiceId":null,"OrderNo":242,"Fk_SiteAddressId":null,"Fk_CustomerId":null,"Fk_GanttItemId":null,"AppointmentDateTime":null,"TimestampCreated":null,"CreationDate":null,"TimestampModified":null,"Description":"","EquipmentNeeded":null,"SpecialInstructions":null,"WorkOrderType":"Contract","JobType":null,"HourlyRate":null,"CompletionStatus":null,"TotalEstHrs":null,"TotalActualHrs":null,"WorkToBePerformed":null,"BIllingStatus":null,"OkToBill":null,"WorkOrderStatus":"Scheduled","IsDeleted":false,"IsProposalSort":null,"TotalRecords":6,"IsUserCreator":1,"CreatedBy":"Mndi,Murali","CustomerName":"Mfsi - Mindi M1","StartTime":"10/1/2014 8:00:00 AM"},{"Pk_WorkOrderId":6807,"Fk_CompanyId":null,"Fk_CreatedByUserId":null,"Fk_ProposalId":null,"Fk_InvoiceId":null,"OrderNo":243,"Fk_SiteAddressId":null,"Fk_CustomerId":null,"Fk_GanttItemId":null,"AppointmentDateTime":null,"TimestampCreated":null,"CreationDate":null,"TimestampModified":null,"Description":"","EquipmentNeeded":null,"SpecialInstructions":null,"WorkOrderType":"Contract","JobType":null,"HourlyRate":null,"CompletionStatus":null,"TotalEstHrs":null,"TotalActualHrs":null,"WorkToBePerformed":null,"BIllingStatus":null,"OkToBill":null,"WorkOrderStatus":"Scheduled","IsDeleted":false,"IsProposalSort":null,"TotalRecords":6,"IsUserCreator":1,"CreatedBy":"Mndi,Murali","CustomerName":"Mfsi - Murli Mindi","StartTime":"8/1/2014 8:00:00 AM"},{"Pk_WorkOrderId":6808,"Fk_CompanyId":null,"Fk_CreatedByUserId":null,"Fk_ProposalId":null,"Fk_InvoiceId":null,"OrderNo":244,"Fk_SiteAddressId":null,"Fk_CustomerId":null,"Fk_GanttItemId":null,"AppointmentDateTime":null,"TimestampCreated":null,"CreationDate":null,"TimestampModified":null,"Description":"adding a new description for this field user.","EquipmentNeeded":null,"SpecialInstructions":null,"WorkOrderType":"Contract","JobType":null,"HourlyRate":null,"CompletionStatus":null,"TotalEstHrs":null,"TotalActualHrs":null,"WorkToBePerformed":null,"BIllingStatus":null,"OkToBill":null,"WorkOrderStatus":"Scheduled","IsDeleted":false,"IsProposalSort":null,"TotalRecords":6,"IsUserCreator":1,"CreatedBy":"Mndi,Murali","CustomerName":"Mindi, Shiv","StartTime":"10/2/2014 8:00:00 AM"},{"Pk_WorkOrderId":6808,"Fk_CompanyId":null,"Fk_CreatedByUserId":null,"Fk_ProposalId":null,"Fk_InvoiceId":null,"OrderNo":244,"Fk_SiteAddressId":null,"Fk_CustomerId":null,"Fk_GanttItemId":null,"AppointmentDateTime":null,"TimestampCreated":null,"CreationDate":null,"TimestampModified":null,"Description":"adding a new description for this field user.","EquipmentNeeded":null,"SpecialInstructions":null,"WorkOrderType":"Contract","JobType":null,"HourlyRate":null,"CompletionStatus":null,"TotalEstHrs":null,"TotalActualHrs":null,"WorkToBePerformed":null,"BIllingStatus":null,"OkToBill":null,"WorkOrderStatus":"Scheduled","IsDeleted":false,"IsProposalSort":null,"TotalRecords":6,"IsUserCreator":1,"CreatedBy":"Mndi,Murali","CustomerName":"Mindi, Shiv","StartTime":"10/2/2014 8:00:00 AM"},{"Pk_WorkOrderId":6809,"Fk_CompanyId":null,"Fk_CreatedByUserId":null,"Fk_ProposalId":null,"Fk_InvoiceId":null,"OrderNo":245,"Fk_SiteAddressId":null,"Fk_CustomerId":null,"Fk_GanttItemId":null,"AppointmentDateTime":null,"TimestampCreated":null,"CreationDate":null,"TimestampModified":null,"Description":"","EquipmentNeeded":null,"SpecialInstructions":null,"WorkOrderType":"Contract","JobType":null,"HourlyRate":null,"CompletionStatus":null,"TotalEstHrs":null,"TotalActualHrs":null,"WorkToBePerformed":null,"BIllingStatus":null,"OkToBill":null,"WorkOrderStatus":"Scheduled","IsDeleted":false,"IsProposalSort":null,"TotalRecords":6,"IsUserCreator":1,"CreatedBy":"Mndi,Murali","CustomerName":"Sudhansu-Dummy test","StartTime":"10/5/2014 1:00:00 PM"},{"Pk_WorkOrderId":6809,"Fk_CompanyId":null,"Fk_CreatedByUserId":null,"Fk_ProposalId":null,"Fk_InvoiceId":null,"OrderNo":245,"Fk_SiteAddressId":null,"Fk_CustomerId":null,"Fk_GanttItemId":null,"AppointmentDateTime":null,"TimestampCreated":null,"CreationDate":null,"TimestampModified":null,"Description":"","EquipmentNeeded":null,"SpecialInstructions":null,"WorkOrderType":"Contract","JobType":null,"HourlyRate":null,"CompletionStatus":null,"TotalEstHrs":null,"TotalActualHrs":null,"WorkToBePerformed":null,"BIllingStatus":null,"OkToBill":null,"WorkOrderStatus":"Scheduled","IsDeleted":false,"IsProposalSort":null,"TotalRecords":6,"IsUserCreator":1,"CreatedBy":"Mndi,Murali","CustomerName":"Sudhansu-Dummy test","StartTime":"10/5/2014 1:00:00 PM"}]"
like image 313
Bharat Sewani Avatar asked Oct 06 '14 06:10

Bharat Sewani


People also ask

Why is JSON parse failing?

SyntaxError is an inherited object of the main error object The main reason behind the error is usually a mistake in the JSON file syntax. You mess up and put a “ instead of a ' and you invite to face the SyntaxError JSON. parse: unexpected character .

How do I fix parse error on Iphone?

The best ways to fix the cannot parse response in Safari Browser includes, Checking your Internet Connection, Clearing Cookies and Website Data, Quitting and Relaunching Safari, and Checking DNS and Using Google DNS.

What is JSON parsing in iOS?

JSON parsing in Swift is a common thing to do. Almost every app decodes JSON to show data in a visualized way. Parsing JSON is definitely one of the basics you should learn as an iOS developer. Decoding JSON in Swift is quite easy and does not require any external dependencies.

Is JSON parse blocking or not?

So yes it JSON. parse blocks. Parsing JSON is a CPU intensive task, and JS is single threaded. So the parsing would have to block the main thread at some point.


1 Answers

The JSON data is valid but when strings that look like Dates or Strings are present within a HTML node both the iPad and iPhone will automatically create clickable links. So basically your JSON is getting mangled when you put it into a standard HTML DOM node.

JS fiddle that shows it working on Desktop: http://jsfiddle.net/8wptohs0/1/

This same JS fiddle does not work on iPhone simulator (there was no alert): (If you look closely you can see the simulator has turned the StartDate field data into blue clickable links) iPhone JSON parse error

If I remove the StartTime property data, it works on the desktop and the iPhone http://jsfiddle.net/8wptohs0/2/

JSON.parse working on iPhone

To fix this, there are some meta tags that should do the trick - you may have to experiment on which ones work for you.

<meta name="format-detection" content="telephone=no"> <meta name="format-detection" content="date=no"> <meta name="format-detection" content="address=no">

However it is worth saying that when inserting serve side data into javascript a data- attribute or inline JS is a more commonly used method - for exactly these kind of reasons.

like image 131
Eamonn Gahan Avatar answered Oct 25 '22 10:10

Eamonn Gahan