Reprinted: https: //blog.csdn.net/u011280342/article/details/79789379
There is a data parameter in the jquery ajax which is the data to the server of the customer
we look at the first common wording:
A front-end code: 2 var username = $ ( '# phone_email_num' ) .val (); . 3 var pwd = $ ( '# password' ) .val (); . 4 $ .ajax ({ . 5 URL: 'the login.php' , . 6 type: 'POST' , . 7 Data: {username: username, pwd: pwd}, // this is the object json . 8 Success: function (Data)} {...... . 9 )}; 10 . 11 backend Code: 12 we print values over post 13 is the dump ($ _ the pOST); 14 results: 15 the Array 16 ( . 17 [username] => 18711111111 18 [pwd] => 123456 19 )
We look at the second writing:
Front-end code $ .ajax ({ URL: 'the login.php' , type: 'POST' , Data: the JSON.stringify ({A: 'A', B: 'B'}), // this is json string contentType : 'file application / JSON', // predetermined value is passed JSON Success: function (Data) {...} )}; back-end code: this time the dump ($ _ POST); result: the Array ( ) nothing , we can use the following method: $ _POST = of json_decode (file_get_contents ( 'PHP: // INPUT'), to true ); then dump ($ _ POST); result: the Array ( [A] => A [B] => b )
ajax first case of default is application / x-www-form-urlencoded submission. That is the common form submission. Use $ _POST way in PHP can easily get, if you use an ajax application / json way, remember that data argument is a string type. Use JSON.stringify () to change my
Reference: HTTPS: //blog.csdn.net/m0_37572458/article/details/78622668 locationNum = FPS = 6 & 1?
Https://www.cnblogs.com/CyLee/p/7644380.html
https://segmentfault.com/ a / 1190000014126990? utm_source = index- hottest