We're using php-framework "slim" to build an e-shop. Now we are meeting a problem that we can send a request to server and modify the database(we checked table and it is changed indeed), whereas web end can't get the response from the database(iOS and android end can both get it). Here is the part of the code which sends the request, updates database and gets the response:
$app->post('/tblUser', function($request, $response, $args) {
get_tblUser_id($request->getParsedBody());
});
function get_tblUser_id($data)
{
$db = connect_db();
$sql = "update tblphoneverify set dtCreate = NOW() where strPhone = $data[phone]";
$db->query($sql);
$updateId = $db->affected_rows;
$db = null;
$msg = array(
'stat' => '',
'msg' => ''
);
$msg['stat'] = '1';
$msg['msg'] = 'registration success';
return json_encode($msg);
}
then this ajax segment triggers the click event to execute post and receives the state of the result:
$(function(){
$("#getcheck").click(function(){
$.ajax({
type:"post",
url:"http://192.168.1.108/blue/public/tblUser",
data: {"phone":"13331111111"},
dataType:"json",
//async:false,
contentType: "application/x-www-form-urlencoded",
success:function(data){
alert(1);
},
error:function(XMLHttpRequest, textStatus, errorThrown){
alert(XMLHttpRequest.readyState);
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.statusText);
alert(XMLHttpRequest.responseText);
alert(textStatus);
alert(errorThrown);
}
})
})
})
the code always skips the "success" part and jumps to "error" directly. So what is wrong with our code? Thanks in advance.