Ajax transmits parameters to the backend controller through post. how can I obtain the passed parameters?

Source: Internet
Author: User
Ajax transmits parameters to the backend controller through post. how to obtain the passed parameters ajax:
$. Ajax ({
Url: 'Index. php? C = MapsApi & m = getLocation ',
Type: 'post ',
// DataType: 'json ',
Timeout: 3000,
Data: {name_province: name_province },
Success: function (msg ){
Alert ("dddd" + unescape (msg ));
},
Error: function (e ){
Alert (JSON. stringify (e ));
}
});

Php implementation


Reply to discussion (solution)

Ajax uses post to submit the REQUEST. The $ _ POST variable can be used in the controller (you can also use $ _ REQUEST ).
Print_r ($ _ POST );

Url: 'Index. php? C = MapsApi & m = getLocation ',
Use $ _ GET for c/m parameters

Data: {name_province: name_province },

Name_province $ _ POST

In fact, ajax submission is the same as form submission data, but ajax requests do not control browser navigation. if your server sets a 3xx response header, you can directly obtain the html code of the page to jump.

Echo $ _ POST ['name _ province '];
?>

$ _ POST ['name _ province ']

Type: 'post', indicating the use of post
Data: {name_province: name_province}, parameters and values

So php can write data like this.

 

Now we have solved the problem. The get method is used:
The URL format is
Url: 'Index. php? C = MapsApi & m = getLocation & name_province = '+ name_province,
Type: 'GET ',
$ _ GET ['name _ province '] can be used in the background to obtain the value;
The get method needs to splice the url and return the obtained data to ajax using exit ('json _ encode ($ info )');

$ _ POST ['name _ province ']

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.