gpt4 book ai didi

javascript - JSON.parse 不适用于 iPad safari

转载 作者:可可西里 更新时间:2023-11-01 13:54:04 26 4
gpt4 key购买 nike

我正在执行一个 ajax 调用,在 success 函数中我正在使用 JSON.Parse 函数。但问题是 JSON.parse功能在除 iPad-Safari 浏览器(iPad 版本~7.0.6)之外的任何地方都有效。在 iPad Safari 中,我的代码在我使用 JSON 的行之后。 Parse 似乎没有被执行。我在 JSON.Parse 行下尝试了一些消息 alert 但没有运气。我们能找到解决方法吗这个问题?

提前致谢。

这是我正在运行的脚本:

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

$('#divWOListForFE').html()如下

"[{"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"}]"

最佳答案

JSON 数据是有效的,但是当看起来像日期或字符串的字符串出现在 HTML 节点中时,iPad 和 iPhone 都会自动创建可点击的链接。所以当您将 JSON 放入标准 HTML DOM 节点时,基本上您的 JSON 会被破坏。

显示它在桌面上工作的 JS fiddle : http://jsfiddle.net/8wptohs0/1/

同样的 JS fiddle 在 iPhone 模拟器上不起作用(没有警报):(如果你仔细观察,你会发现模拟器已经将 StartDate 字段数据变成了蓝色的可点击链接) iPhone JSON parse error

如果我删除 StartTime属性数据,它适用于桌面和 iPhone http://jsfiddle.net/8wptohs0/2/

JSON.parse working on iPhone

要解决此问题,有一些元标记应该可以解决问题 - 您可能需要试验哪些适合您。


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

然而,值得一提的是,当将服务端数据插入 javascript 时,一个 data-属性或内联 JS 是更常用的方法 - 正是出于这些原因。

关于javascript - JSON.parse 不适用于 iPad safari,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26211186/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com