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 ']