Jqueryajaxpost is submitted to the controller of ThinkPHP, but $ _ POST cannot be obtained. what should I do?-php Tutorial

Source: Internet
Author: User
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.

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.