Jqueryajaxpost is submitted to the controller of ThinkPHP, but $ _ POST cannot be obtained. how should I write it? the front-end js is like this?
var uid = '10002'; var a = 'get_users'; jQuery.ajax({ url: "http://localhost:8099/thinkphp111/index.php?s=/Index/index.html", type: "POST", data: { uid: uid, a: a }, success: function (jsonResult) { alert(jsonResult); }, error: function (e) { alert(e); } });
Php is like this.
aa();}
However, the result returned after execution is null. Normally, 'get _ users' is returned '. Why?
Reply to discussion (solution)
Index. php? S =/Index/index.html
Why? How do I write a route?
Are you sure the index method is executed?
I'm sure the method has been executed.
Because on the php side, if I assign a value to $ _ POST ['A'] directly, for example, $ _ POST ['A'] = 'getusers'
Then I will execute that js in html. Now alert comes out to getusers. The command is executed. Only PHP cannot obtain the post value.
I have not set a route.
You mean
Namespace Home \ Controller;
Use Think \ Controller;
$ _ POST ['A'] = 'getusers ';
Class IndexController extends HomeController {
Public function aa ()
{
$ Output = array ();
$ A = $ _ POST ['A']? $ _ POST ['A']: '';
Echo $;
}
Public function index (){
$ This-> aa ();
}
Then, the address bar of the browser is http: // localhost: 8099/thinkphp111/index. php? S =/Index/index.html
Is this executed?
Just pull the image.
In THinkPHP, do not use parameter names such as a, m, and g for parameters passed by ajax. this is the default TP acquisition method, controller, and group, you can replace a with another one.
Wow, thank you very much for a583049958. All at once, it was successfully pulled. This is indeed a problem.