在學習jQuery的ajax遇到了問題:$.ajaxSetup({ })取表單的數據不成功。代碼如下:' <form> user:<input type="text" name="user"> email:<input type="text" name="email"> <input type="button" value='提交'> </form> <script type="text/javascript"> $(function(){ var to=$("form input[type=button]"); $.ajaxSetup({ type:'POST', url:"file/testAjax.php", data:$("form").serialize() }); to.click(function(){ $.ajax({ success:function(response,status,xhr){ alert(response); } }); }); })</script>testAjax.php:<?phpecho $_POST['user'].' - '.$_POST['email'];?>截圖顯示取的數據為空。把ajaxSetup這塊放在click函數里能取到數據,但是這樣ajaxSetup就失去意義了。小弟不才,請各位指教一下是什么原因。
$.ajaxSetup({ })取表單的數據不成功,為什么?
楊__羊羊
2019-02-27 16:22:51