About parsererror SyntaxError: Unexpected end of input (CI with Jquery&ajax ) -
i don't understand error .
i use codeigneter , jquery&ajax
error parsererror
personedit.php
$(document).ready(function(){ var options = { datatype : 'json', beforesubmit: saveshowrequest, // pre-submit callback success: saveshowresponse, //post-submit callback error: function (xhr, ajaxoptions, thrownerror){ //alert('error !!'++ xhr.statustext); //alert(thrownerror); $('#output_test').html('<h2>error !!!!: ' + xhr.statustext +'</h2>'+thrownerror ); } // other available options: //url: url // override form's 'action' attribute //type: type // 'get' or 'post', override form's 'method' attribute //datatype: null // 'xml', 'script', or 'json' (expected server response type) //clearform: true // clear form fields after successful submit //resetform: true // reset form after successful submit //$.ajax options can used here too, example: //timeout: 3000 }; $('#myeditpersonform').ajaxform(options); }); // pre-submit callback function saveshowrequest(formdata, jqform, options) { // formdata array; here use $.param convert string display // form plugin automatically when submits data var querystring = $.param(formdata); // jqform jquery object encapsulating form element. access // dom element form this: // var formelement = jqform[0]; alert('about submit: \n\n' + querystring); // here return false prevent form being submitted; // returning other false allow form submit continue return true; } // post-submit callback function saveshowresponse() { // if ajaxform method passed options object datatype // property set 'json' first argument success callback // json data object returned server //alert display alert('success exemple return respone'); //html display $('#output_test').html('success exemple return respone '); }
ajax_post.php // ci
function update_person(){ // set common properties // run validation // save data $id = $this->input->post('id'); $person = array('name' =$this->input->post('name'), 'gender' =$this->input->post('gender'), 'dob' =date('y-m-d', strtotime($this->input->post('dob')))); $this->personmodel->update($id,$person); // set user message $data['message'] = '<div class="success">update person success</div>'; }
$('#output_test').html('<h2>error !!!!: ' + xhr.statustext +'</h2>'+thrownerror); alert(xhr.responsetext);
alert(xht.responsetext); ok . can send responsetext (no error)
and why cannot use success: saveshowresponse,
this error means response coming url not json, there's error attempting parse such.
either in network panel (easier), or adjust error handler see response server returning, looking @ responsetext
this:
$('#output_test').html('<h2>error !!!!: ' + xhr.statustext +'</h2>'+thrownerror); alert(xhr.responsetext);
Comments
Post a Comment