jQuery AJAX无法在iPhone safari上运行



所以我正在使用jQuery进行Ajax调用,它在所有桌面浏览器和Android的chrome上都可以正常工作,但是它在iOS上的Safari中不起作用有什么想法吗?

$(document).ready(function(){
(function($){
function processForm( e ){
var callid = $('.callid').val();
var pin = $('.pin').val();
var urlFinal = callid+'/'+pin;
$.ajax({
url: 'http://URLHERE/getHash/' + urlFinal,
dataType: 'text',
type: 'get',
contentType: 'application/x-www-form-urlencoded',
success: function( data, textStatus, jQxhr ){
var urlResponse = JSON.parse(data);
console.log("WORKS! " + urlResponse.streamFileUrl);
$('.overlay').show();
playVideo(urlResponse);
},
error: function( jqXhr, textStatus, errorThrown ){
console.log('INCORRECT DETAILS ');
$('.incorrect').show()
}
});
e.preventDefault();
}
$('#form').submit( processForm );
})(jQuery);
})

至少从多余的额外负载处理程序中解包您的代码,您很少需要在负载处理程序中使用 IIFE

$(document).ready(function(){  // load handler 
(function($){  // remove

将 preventDefault 移动到如果其余代码失败时提交将停止的位置,并删除不必要的垃圾:

dataType: 'text', // jQUery will figure this out based on response
type: 'get', // default
contentType: 'application/x-www-form-urlencoded', // only needed for POST
var urlResponse = JSON.parse(data); // if text is left out, JSON is returned 

这是一个更短更干净的版本

$(function() { // shorter version of $(document).ready(function
$('#form').on("submit", function(e) {
e.preventDefault(); // belongs HERE
var callid = $('.callid').val();
var pin = $('.pin').val();
var urlFinal = callid + '/' + pin;
$.ajax({
url: 'http://URLHERE/getHash/' + urlFinal,
success: function(data, textStatus, jQxhr) {
console.log("WORKS! " + data.streamFileUrl); // is already JSON
$('.overlay').show();
playVideo(urlResponse);
},
error: function(jqXhr, textStatus, errorThrown) {
console.log('INCORRECT DETAILS ');
$('.incorrect').html(errorThrown).show()
}
});
});
});

相关内容

最新更新