Jquery ajax cannot pass the value to the background using the get method, why

Source: Internet
Author: User
Jquery ajax cannot pass the value to the background using the get method. why is as follows:
// The following is the js method
Function login (){
$. Ajax ({
Type: "get ",
Url: 'valid. php ',
Data: "username = admin ",
DataType: "json ",
Success: ajaxComplete (result ),
Error: ajaxError (response )});
});
}

// The following is valid. php
Echo $ _ GET ['username'];
?>

After the login () method is triggered, the page reports the error Notice: Undefined index: username, which means this parameter cannot be found. why !!


Reply to discussion (solution)

Data: "username = admin", the error here is either your data "username: admin"
Or serialize it first.

You have written an error in JavaScript. how can you get the result?

Function login () {$. ajax ({type: "get", url: 'valid. php ', data: "username = admin", dataType: "json", success: ajaxComplete, error: ajaxError });}

Both success and error require callback functions.
You can either assign a function name or directly define an anonymous function.

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.