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.