javascript JSON.parse在iPad Safari上不起作用

lyr7nygr  于 2023-04-28  发布在  Java
关注(0)|答案(2)|浏览(197)

我正在做一个 AJAX 调用,在success函数中我使用了JSON.Parse函数。但问题是JSON.parse函数在任何地方都可以工作,除了iPad-Safari浏览器iPad Version~7.0.6)。在iPad Safari中,我在使用JSON.Parse的行之后的代码似乎没有执行。我尝试了alert,在JSON.Parse行下有一些消息,但没有运气。我们能找到解决这个问题的办法吗?
先谢谢你了。
下面是我正在运行的SCRIPT

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

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

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

t9aqgxwy1#

JSON数据是有效的,但当HTML节点中出现类似日期或字符串的字符串时,iPad和iPhone都会自动创建可点击的链接。所以当你把JSON放到一个标准的HTML DOM节点时,基本上你的JSON会被破坏。
JS fiddle显示它在桌面上工作:http://jsfiddle.net/8wptohs0/1/
同样的JS fiddle在iPhone模拟器上不起作用(没有警报):(如果您仔细观察,可以看到模拟器已将StartDate字段数据转换为蓝色可单击链接)x1c 0d1x
如果我删除StartTime属性数据,它在桌面和iPhone http://jsfiddle.net/8wptohs0/2/上都能正常工作

为了解决这个问题,有一些 meta标签应该可以解决这个问题-你可能需要试验哪些标签适合你。
<meta name="format-detection" content="telephone=no"> <meta name="format-detection" content="date=no"> <meta name="format-detection" content="address=no">
然而,值得一提的是,当将服务端数据插入javascript时,data-属性或内联JS是一种更常用的方法--正是出于这些原因。

g52tjvyc

g52tjvyc2#

对我来说,这是我在头部部分工作的 meta标签。

<head>
<meta name="format-detection" content="telephone=no">
</head>

相关问题