简体   繁体   中英

Syntax error on Jquery form post

I've got this code below which is suppose to be submitting a form via Jquery's post.

<script>
/* attach a submit handler to the form */
$("#contactForm").submit(function(event) {
  /* stop form from submitting normally */
  event.preventDefault();
  /* get some values from elements on the page: */
  var $form = $( this ),
      url = $form.attr( 'action' );

  /* Serialize Data */
  var senddata = $form.serializeArray();

  /* Send the data using post */
  var posting = $.post( url, senddata);

  /* Put the results in a div */
  posting.done(function( data ) {
    var content = $( data ).find( '#content' );
    $( "#result" ).empty().append( content );
  });
});
</script>

But every time I try and submit I get this error in the console:

Error: Syntax error, unrecognized expression: Array ( [name] => name [email] => dsf@dsfsd.com [number] => 23456567 [query] => query )

Any suggestions?

Thanks.

也许您应该尝试将发布更改为:

var posting = $.post( url, { 'data' : senddata} );

Mike put me on the right track. It was the post back from the PHP file that was causing the issue when trying to parse it back into an object. Thanks for your help guys

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM