How does php handle forms submitted by ajax?

Source: Internet
Author: User
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 ;}

  1. Provide yoursuccessFunction.

  2. Provide that your backend is in useecho json_encode($respond);.

Follow up on your updated content:

  1. Providebutton_signupThe HTML code of this DOM node.

  2. Provided in the requestlogupBusiness.phpIn this PHP file, the back-end output content, instead of providing your PHP source code.

However, I guess your current Codebutton_signupIt may betype=submitAfter 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.