Ajax - url不工作 - Pl帮助我

时间:2018-01-07 11:32:03

标签: php

$.ajax({
   type: 'POST',
   url: 'http://localhost/php/chk.php',
   data: formdata,
   dateType: 'json',
   success: function(resp) {
       if ( resp == true ) { alert ('ok'); } else { alert ('not ok'); }
   }
});


 <form id="contact" action="#" method="post">
   <input name="name" type="text"/>
   <input name="email_address" type="text"/>
   <textarea name="message"/></textarea>
   <button id="submit">submit</button>
</form>

1 个答案:

答案 0 :(得分:0)

如果formdata应该是FormData对象的实例,那么也许 你可以这样做

$.ajax({
   type: 'POST',
   url: 'http://localhost/php/chk.php',
   data: ( new FormData( document.getElementById('contact') ) ),
   dataType: 'json',
   success: function( resp ) {
       if ( resp == true ) { alert ('ok'); } else { alert ('not ok'); }
   }
});