Xhr does not respond when ajax is used.

Source: Internet
Author: User
1. ajax is used in the project. Results during the test, the page was found to be different in the two browsers: The 360 browser can successfully achieve the pop-up window (alert) effect, but the Firefox browser has no effect at all. But they all share a common feature: in the browser's debugging mode (F12) network option xhr...

1. ajax is used in the project. Results during the test, the page was found to be different in the two browsers: The 360 browser can successfully achieve the pop-up window (alert) effect, but the Firefox browser has no effect at all. However, they all share a common feature: No data is obtained under the xhr network option of the browser's debugging mode (F12, data, including index homepage (POST), can be seen in all parts of the network, such as html, css, and js. Other resources are obtained by GET.
2. if ThinkPHP's automatic verification function is used, the error will automatically return information, including no user name or password, but I did not compare the account and password, I also don't know why I lost data randomly in the user name and password in the 360 browser. I found a blank alert dialog box, and I don't know what the problem is?
3.360 when the alert dialog box appears in the browser, xhr still has data, but when you click OK in the alert dialog box, the xhr data disappears.

The code is as follows:
(1) login. js

// Front-end login service class var login = {checkUser: function () {// Obtain the input data in the logon page var userName = $ ('input [name = "username"] '). val (); var userPass = $ ('input [name = "userpass"] '). val (); // use ajax var url = "/stfjzd-15/index. php/Home/Index/checkUser "; var data = {" username ": userName," userpass ": userPass}; $. post (url, data, function (result) {// $ ("# result" ).html (data.info ). show (); // $ ("# result "). fadeOut (4000); if (result. status) {alert (result.info);} else {// alert (2); alert (result.info) ;}}, "json ");}}

(2) IndexController. class. php


  Display ();} // user verification public function checkUser () {// receives the variable. the default htmlspecialchars filter $ userName = I ("post. username "); $ userPass = I (" post. userpass "); $ User = D (" Stuser "); // automatic verification of ThinkPHP must use create () to enable if (! $ User-> create () {return $ this-> error ($ User-> getError (); // exit ($ User-> getError ());}} // empty operation public function _ empty () {echo "the page does not exist. check whether the path you entered is correct. I want to return to the homepage ";}}

(3) StuserModel. class. php


  DB = M ("Stuser");} // the form of ThinkPHP automatically verifies protected $ _ validate = array ("username", "require ", "username cannot be blank"), array ("userpass", "require", "password cannot be blank"),) ;}?>

Reply content:

1. ajax is used in the project. Results during the test, the page was found to be different in the two browsers: The 360 browser can successfully achieve the pop-up window (alert) effect, but the Firefox browser has no effect at all. However, they all share a common feature: No data is obtained under the xhr network option of the browser's debugging mode (F12, data, including index homepage (POST), can be seen in all parts of the network, such as html, css, and js. Other resources are obtained by GET.
2. if ThinkPHP's automatic verification function is used, the error will automatically return information, including no user name or password, but I did not compare the account and password, I also don't know why I lost data randomly in the user name and password in the 360 browser. I found a blank alert dialog box, and I don't know what the problem is?
3.360 when the alert dialog box appears in the browser, xhr still has data, but when you click OK in the alert dialog box, the xhr data disappears.

The code is as follows:
(1) login. js

// Front-end login service class var login = {checkUser: function () {// Obtain the input data in the logon page var userName = $ ('input [name = "username"] '). val (); var userPass = $ ('input [name = "userpass"] '). val (); // use ajax var url = "/stfjzd-15/index. php/Home/Index/checkUser "; var data = {" username ": userName," userpass ": userPass}; $. post (url, data, function (result) {// $ ("# result" ).html (data.info ). show (); // $ ("# result "). fadeOut (4000); if (result. status) {alert (result.info);} else {// alert (2); alert (result.info) ;}}, "json ");}}

(2) IndexController. class. php


  Display ();} // user verification public function checkUser () {// receives the variable. the default htmlspecialchars filter $ userName = I ("post. username "); $ userPass = I (" post. userpass "); $ User = D (" Stuser "); // automatic verification of ThinkPHP must use create () to enable if (! $ User-> create () {return $ this-> error ($ User-> getError (); // exit ($ User-> getError ());}} // empty operation public function _ empty () {echo "the page does not exist. check whether the path you entered is correct. I want to return to the homepage ";}}

(3) StuserModel. class. php


  DB = M ("Stuser");} // the form of ThinkPHP automatically verifies protected $ _ validate = array ("username", "require ", "username cannot be blank"), array ("userpass", "require", "password cannot be blank"),) ;}?>

Use$this->ajaxReturn()Orjson_encodeTry

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.