jQuery Ajax form submit error handling -


i have following code:

var url = "save.php"; // script handle form input.     $.ajax({         type: "post",         url: url,         data: $("#frmsurvey").serialize(), // serializes form's elements.          success: function(){             alert('success');           },         error: function(){             alert( "request failed: " );           }          });  

now, works fine when submitting data db - however, when deliberately change save.php file data isn't submitted, still success alert.

code save file below:

$proc = mysqli_prepare($link, "update tresults set ip = ?, browser = ?, q1 = ?, q2 = ?, q3 = ?, q4 = ?, q5 = ?, q6 = ?, q7 = ?, q8 = ?, q9 = ?, q10 = ?, q11 = ?, q12 = ?, q13 = ?, q14 = ?, q15 = ?, q16 = ?, q17 = ?, q18 = ?, q19 = ?, q20 = ?, q21 = ?, q22 = ?, q23 = ?, q24 = ?, q25 = ?, q26 = ?, q27 = ?, q28 = ?, q29 = ?, q30 = ?, q31 = ?, q32 = ?, q33 = ?, q34 = ?, q35 = ?, q36 = ?, q37 = ?, q38 = ?, q39 = ?, q40 = ?, q41 = ?, q42 = ?, q43 = ?, q44 = ?, q45 = ?, q46 = ?, q47 = ?, q48 = ?, q49 = ?, q50 = ?, q51 = ?, q52 = ?, q53 = ?, q54 = ?, q55 = ? respondent_id = ?;");     mysqli_stmt_bind_param($proc, "ssiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiissi", $ip, $browser, $q1, $q2, $q3, $q4, $q5, $q6, $q7, $q8, $q9, $q10, $q11, $q12, $q13, $q14, $q15, $q16, $q17, $q18, $q19, $q20, $q21, $q22, $q23, $q24, $q25, $q26, $q27, $q28, $q29, $q30, $q31, $q32, $q33, $q34, $q35, $q36, $q37, $q38, $q39, $q40, $q41, $q42, $q43, $q44, $q45, $q46, $q47, $q48, $q49, $q50, $q51, $q52, $q53, $q54, $q55, $respondent_id);     mysqli_stmt_execute($proc);     $mysql_error = mysqli_error($link);     if ($mysql_error!="") {         printf("unexpected database error: %s\n", $mysql_error);         mysqli_stmt_close($proc);         mysqli_clean_connection($link);         exit();     } else     {         mysqli_stmt_close($proc);         mysqli_clean_connection($link);         update_completion_status($respondent_id, 'started');         header("location: index.php?r=".$rguid);     } 

where going wrong?

you have change way server responds , make return different http header implies error rather 200 ok.

check server returns, , see it's returning 404 status non-existing pages.

useful comments,

when this, doesn't save data 'success' message showing.

that success different success of db queries. thats success of ajax call. if want check errors of mysql, need this answer. see how return success or fail using php file, , process response using jquery.

as shown in answer, in link in above comment, success of ajax can seen different success returned php. keep check in php file if db queries executed successfully, if not return message fail, if return message fail, ajax call returns success, because ajax call successfull of course. that's how got php files.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -