![](/img/trans.png)
[英]$(window).load(function() event not firing on Safari Mobile
[英]AJAX not firing in Safari or Safari mobile
由於某些原因,我的AJAX事件不會在Mac或iPad / iPhone的Safari中觸發。 我對此並不陌生,所以可能是(可能是)程序員的錯誤,但這是我的代碼:
<form class='send-form'>
<input type="hidden" name="csv-val" value="">
<input type="hidden" name="img-val" value="">
<button type='button' class='send-it' onclick='$(sendTheData(event))'>
Manual Submit
</button>
</form>
<script>
function sendTheData(event){
var sendButton = $(event.target);
var theForm = sendButton.parents('form');
var theFormClass = sendButton.parents('form').attr('class');
console.log("Parent form is " + theFormClass);
$.ajax({
async: "true",
type: 'GET',
url: 'save.php',
data: $(theForm).serialize()
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
return false;
}
</script>
請注意,帶有send-form
類的元素是通過其他jQuery腳本附加到文檔的,並且在初始加載時不在頁面上,因此可能會影響事情。 我不確定。
嘗試添加失敗回調,可能會出現一些錯誤...您可以在http://api.jquery.com/jQuery.ajax/上找到該示例
腳步:
onclick
屬性更正為onclick="sendTheData(event);"
url
是否正確。 GET
更改為POST
。 關於表單類的注意事項:您可以將id
設置為特定表單,然后將變量綁定到該id
而不是class
。 嘗試避免使用parent()
和類似的函數,因為它們使用了過多的資源(要遍歷所有元素,然后遍歷父元素,然后找到正確的元素,而不是直接針對正確的對象) 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.