i new ajax.
what trying here bringing variables php file i've wrote process html form data mysql db table.
after research concluded need use json (first time) , must add part datatype:'json'
ajax.
my problem after adding part, no more able submitting form!
can please let me know doing wrong here? need process php
code , return 3 mentioned variables jquery
variable can stuff them.
thank in advance.
ajax:
var form = $('#contact-form'); var formmessages = $('#form-messages'); form.submit(function(event) { event.preventdefault(); var formdata = form.serialize(); $.ajax({ type: 'post', url: form.attr('action'), data: formdata, datatype: 'json', //after adding part, can't anymore submit form success: function(data){ var message_status = data.message_status; var duplicate = data.duplicate; var number = data.ref_number; //do other stuff here alert(number+duplicate+number); } }) });
php:
//other code here $arr = array( 'message_status'=>$message_status, 'duplicate'=>$duplicate, 'ref_number'=>$ref_number ); echo json_encode($arr);
the way have specified form method incorrect. change
type: 'post',
to
method: 'post',
and give try. can log response , post here ? also, check console errors.
Comments
Post a Comment