How does the server side send data to the client?

Source: Internet
Author: User
I used the Post method to send a user name and password to the server side, want to use PHP to implement the server response to the behavior, return a successful login string, how to do it? And how does the client get the string?


Reply to discussion (solution)

To see W3school.

Write a demo, enter the username=fdipzone,password=123456 server back to return success, or return failure.
client.html

   
 
    Client Post        

Username

Password


server.php
 
  

Ajax? Let's talk about how you post to the server.



 
  



In order to realize that the client sends the data to the server, the server responds to the data to the client, and finally the client sends the result of the response data to the server side.
The total is the tri-rounds data exchange process, how to achieve this?

Three processes want to be able to achieve the entire process by clicking the login button once.

You just press a button, call a method, and then callback other methods inside the method. Until the process is finished.
Can write like this.

function Fsubmit () {
$.post ("server.php", {username: $ ("#username"). Val (), Password: $ ("#password"). Val ()},function (ret) {
if (ret.success==true) {
Log in successfully, the second method can be called here
Dosecondfunc ();
}else{
Alert (' login fail ');
}
}, ' json ');
}

function Dosecondfunc () {
Do STH
If there is, you can call thrid function here again
}

Can I add parameters to the address, such as "Server.php?a=1"?

Can I add parameters to the address, such as "Server.php?a=1"?



Yes, but a needs to use $_get[' a '] to get

        


$array = Array (    ' get ' = = $_get[' gettest '],    ' post ' = ' $_post[' test '); Echo Json_encode ($array);


After an afternoon, I finally figured it out, thank you.

  • 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.