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"}]"
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 .
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.
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.
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.
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)
If I remove the StartTime
property data, it works on the desktop and the iPhone
http://jsfiddle.net/8wptohs0/2/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With