Made a project of his own,
Using jquery's Ajax module to send data to a PHP page,
PHP page uses $_post['] to receive data,
Use echo json_encode ($respond) when returning;
However, it is not normal to print the returned JSON data in the AJAX success function.
And jump is not normal, Ajax is not jump page, right, after returning the results, the page jumps once to the page (refresh).
Did I make a mistake in which link?
Online and so on.
Jquery:
$(function(){ //登陆 $("#button_signip").click(function(){ }); //注册 $("#button_signup").click(function(){ console.log($("#logup_inputUser").value); $.ajax({ type: 'post', ulr: '../service/logupBusiness.php', async: false, data: $("#form_signup").serialize(), beforeSend: function () { }, complete: function () { }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.status); alert(XMLHttpRequest.readyState); alert(textStatus); }, success: function (data, textStatus) { console.log(data);//返回的结果不正常,并不是json console.log(textStatus); alert(data); } }); });});
PHP business logic (logupbusiness.php):
register(array("username"=>$name, "password"=>$password, "email"=>$email)); $res = $bmobUser->login($name,$password); echo json_encode($res);//返回结果,son}catch (Exception $e){ echo $e;}
Reply content:
Made a project of his own,
Using jquery's Ajax module to send data to a PHP page,
PHP page uses $_post['] to receive data,
Use echo json_encode ($respond) when returning;
However, it is not normal to print the returned JSON data in the AJAX success function.
And jump is not normal, Ajax is not jump page, right, after returning the results, the page jumps once to the page (refresh).
Did I make a mistake in which link?
Online and so on.
Jquery:
$(function(){ //登陆 $("#button_signip").click(function(){ }); //注册 $("#button_signup").click(function(){ console.log($("#logup_inputUser").value); $.ajax({ type: 'post', ulr: '../service/logupBusiness.php', async: false, data: $("#form_signup").serialize(), beforeSend: function () { }, complete: function () { }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.status); alert(XMLHttpRequest.readyState); alert(textStatus); }, success: function (data, textStatus) { console.log(data);//返回的结果不正常,并不是json console.log(textStatus); alert(data); } }); });});
PHP business logic (logupbusiness.php):
register(array("username"=>$name, "password"=>$password, "email"=>$email)); $res = $bmobUser->login($name,$password); echo json_encode($res);//返回结果,son}catch (Exception $e){ echo $e;}
Provide your success
function.
Provide the results of your backend in use echo json_encode($respond);
.
Follow up with your updated content:
Provides the button_signup
HTML code for this DOM node with ID.
Provide the content of the logupBusiness.php
backend output when requesting this PHP file, instead of providing you with this PHP source code.
However, in your current code, guess your button_signup
counterpart may be a type=submit
type of button, and then after the point, submitted the form, and then jumped away.
That must be something wrong, but from the information you provide you can't see where there is a problem. You can notice whether the json_encode result is normal, and if JS has other methods to deal with the result.
$.ajax
Success:function (callback) {alert (callback)},
Php:
Echo Json_encode ($str, json_force_object);
Do not post code out of everyone can not help you, if more privacy, you may paste a demo code is also OK, we help you to analyze where the wrong.
Landlord better put the code out