I made a project myself and used the ajax module of jQuery to send data to the php page. The php page uses $ _ POST [& #039; & #039;] to receive data, echojson_encode ($ respond) is used to return data. However, it is not normal to print the returned json data in the success function of ajax. And the jump is not correct... I made a project myself,
Use the ajax module of jQuery to send data to the php page,
The php page uses $ _ POST [''] to receive data,
Use echo json_encode ($ respond );
However, it is not normal to print the returned json data in the success function of ajax.
In addition, the jump is not normal. ajax does not jump to the page, right? After the result is returned, the page jumps to the page once (refresh ).
Which link has an error?
Online.
JQuery:
$ (Function () {// login $ ("# button_signip "). click (function () {}); // register $ ("# 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); // The returned results are not normal, not the 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); // return result, son} catch (Exception $ e) {echo $ e ;}
Reply content:
I made a project myself,
Use the ajax module of jQuery to send data to the php page,
The php page uses $ _ POST [''] to receive data,
Use echo json_encode ($ respond );
However, it is not normal to print the returned json data in the success function of ajax.
In addition, the jump is not normal. ajax does not jump to the page, right? After the result is returned, the page jumps to the page once (refresh ).
Which link has an error?
Online.
JQuery:
$ (Function () {// login $ ("# button_signip "). click (function () {}); // register $ ("# 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); // The returned results are not normal, not the 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); // return result, son} catch (Exception $ e) {echo $ e ;}
Provide yoursuccess
Function.
Provide that your backend is in useecho json_encode($respond);
.
Follow up on your updated content:
Providebutton_signup
The HTML code of this DOM node.
Provided in the requestlogupBusiness.php
In this PHP file, the back-end output content, instead of providing your PHP source code.
However, I guess your current Codebutton_signup
It may betype=submit
After clicking the button of the type, submit the form and jump away ..
There must be a problem at a specific stage, but the information you provide cannot tell where the problem is. You can check whether the json_encode result is normal and whether there are other methods in js to process the result.
$. Ajax
Success: function (callback) {alert (callback )},
Php:
Echo json_encode ($ str, JSON_FORCE_OBJECT );
If you do not post the code, you will not be able to help you. If you are relatively private, you can post a demo to simulate the code.
You 'd better post the code