国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
Reply content:
Home Backend Development PHP Tutorial Using ajax, xhr does not respond

Using ajax, xhr does not respond

Jul 06, 2016 pm 01:51 PM
php thinkphp

1. Ajax is used in the project. As a result, during the test, it was found that the page performed differently in the two browsers: 360 Browser could successfully achieve the pop-up (alert) effect, but Firefox had no effect at all. But they all have one thing in common: no data is obtained under the network option xhr in the browser's debugging mode (F12), but data can be seen in all places on the network, html, css, and js, including index homepage (POST), other resources are obtained through GET.
2. Using the automatic verification function of ThinkPHP, the error will automatically return information, including no username or password entered, but I did not compare the account password, and I don’t know why the username and password in the 360 ??browser I randomly entered the password and found a blank alert dialog box. I don’t know what is going on?
When the alert dialog box appears in the 3.360 browser, xhr still has data, but when OK is clicked on the alert dialog box, the xhr data disappears.
Using ajax, xhr does not respond
Using ajax, xhr does not respond

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

<code>//前端登錄業(yè)務(wù)類(lèi)
var login={
  checkUser:function(){
    //獲取登錄頁(yè)面中的輸入數(shù)據(jù)
    var userName=$('input[name="username"]').val();
    var userPass=$('input[name="userpass"]').val();
    //使用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");
  }
}</code>

(2)IndexController.class.php

<code><?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
  public function index(){
    $this->display();
  }
  //用戶(hù)驗(yàn)證
  public function checkUser(){
    //接收變量,默認(rèn)htmlspecialchars過(guò)濾
    $userName=I("post.username");
    $userPass=I("post.userpass");
    $User=D("Stuser");
    //ThinkPHP的自動(dòng)驗(yàn)證必須使用create()才能啟用
    if(!$User->create()){
      return $this->error($User->getError());
      //exit($User->getError());
    }
  }
  //空操作
  public function _empty(){
    echo "頁(yè)面不存在,請(qǐng)檢查您輸入的路徑是否正確,我要返回<a href='"._PHP_FILE_."' alt='返回首頁(yè)' title='返回首頁(yè)'>首頁(yè)</a>";
  }
}</code>

(3)StuserModel.class.php

<code><?php
  namespace Home\Model;
  use Think\Model;
  //用戶(hù)表模型
  class StuserModel extends Model{
    //構(gòu)造函數(shù)創(chuàng)建模型
    public function __construct(){
      $this->DB=M("Stuser");
    }
    //ThinkPHP的表單自動(dòng)驗(yàn)證
    protected $_validate=array(
      array("username","require","用戶(hù)名不能為空"),
      array("userpass","require","密碼不能為空"),
    );

  }
?></code>

Reply content:

1. Ajax is used in the project. As a result, during the test, it was found that the page performed differently in the two browsers: 360 Browser could successfully achieve the pop-up (alert) effect, but Firefox had no effect at all. But they all have one thing in common: no data is obtained under the network option xhr in the browser's debugging mode (F12), but data can be seen in all places on the network, html, css, and js, including index homepage (POST), other resources are obtained through GET.
2. Using the automatic verification function of ThinkPHP, the error will automatically return information, including no username or password entered, but I did not compare the account password, and I don’t know why the username and password in the 360 ??browser I randomly entered the password and found a blank alert dialog box. I don’t know what is going on?
When the alert dialog box appears in the 3.360 browser, xhr still has data, but when OK is clicked on the alert dialog box, the xhr data disappears.
Using ajax, xhr does not respond
Using ajax, xhr does not respond

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

<code>//前端登錄業(yè)務(wù)類(lèi)
var login={
  checkUser:function(){
    //獲取登錄頁(yè)面中的輸入數(shù)據(jù)
    var userName=$('input[name="username"]').val();
    var userPass=$('input[name="userpass"]').val();
    //使用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");
  }
}</code>

(2)IndexController.class.php

<code><?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
  public function index(){
    $this->display();
  }
  //用戶(hù)驗(yàn)證
  public function checkUser(){
    //接收變量,默認(rèn)htmlspecialchars過(guò)濾
    $userName=I("post.username");
    $userPass=I("post.userpass");
    $User=D("Stuser");
    //ThinkPHP的自動(dòng)驗(yàn)證必須使用create()才能啟用
    if(!$User->create()){
      return $this->error($User->getError());
      //exit($User->getError());
    }
  }
  //空操作
  public function _empty(){
    echo "頁(yè)面不存在,請(qǐng)檢查您輸入的路徑是否正確,我要返回<a href='"._PHP_FILE_."' alt='返回首頁(yè)' title='返回首頁(yè)'>首頁(yè)</a>";
  }
}</code>

(3)StuserModel.class.php

<code><?php
  namespace Home\Model;
  use Think\Model;
  //用戶(hù)表模型
  class StuserModel extends Model{
    //構(gòu)造函數(shù)創(chuàng)建模型
    public function __construct(){
      $this->DB=M("Stuser");
    }
    //ThinkPHP的表單自動(dòng)驗(yàn)證
    protected $_validate=array(
      array("username","require","用戶(hù)名不能為空"),
      array("userpass","require","密碼不能為空"),
    );

  }
?></code>

Try using $this->ajaxReturn() or json_encode

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to handle File Uploads securely in PHP? How to handle File Uploads securely in PHP? Jul 08, 2025 am 02:37 AM

To safely handle PHP file uploads, you need to verify the source and type, control the file name and path, set server restrictions, and process media files twice. 1. Verify the upload source to prevent CSRF through token and detect the real MIME type through finfo_file using whitelist control; 2. Rename the file to a random string and determine the extension to store it in a non-Web directory according to the detection type; 3. PHP configuration limits the upload size and temporary directory Nginx/Apache prohibits access to the upload directory; 4. The GD library resaves the pictures to clear potential malicious data.

How Do You Pass Variables by Value vs. by Reference in PHP? How Do You Pass Variables by Value vs. by Reference in PHP? Jul 08, 2025 am 02:42 AM

InPHP,variablesarepassedbyvaluebydefault,meaningfunctionsorassignmentsreceiveacopyofthedata,whilepassingbyreferenceallowsmodificationstoaffecttheoriginalvariable.1.Whenpassingbyvalue,changestothecopydonotimpacttheoriginal,asshownwhenassigning$b=$aorp

How Do Generators Work in PHP? How Do Generators Work in PHP? Jul 11, 2025 am 03:12 AM

AgeneratorinPHPisamemory-efficientwaytoiterateoverlargedatasetsbyyieldingvaluesoneatatimeinsteadofreturningthemallatonce.1.Generatorsusetheyieldkeywordtoproducevaluesondemand,reducingmemoryusage.2.Theyareusefulforhandlingbigloops,readinglargefiles,or

PHP header location ajax call not working PHP header location ajax call not working Jul 10, 2025 pm 01:46 PM

The reason why header('Location:...') in AJAX request is invalid is that the browser will not automatically perform page redirects. Because in the AJAX request, the 302 status code and Location header information returned by the server will be processed as response data, rather than triggering the jump behavior. Solutions are: 1. Return JSON data in PHP and include a jump URL; 2. Check the redirect field in the front-end AJAX callback and jump manually with window.location.href; 3. Ensure that the PHP output is only JSON to avoid parsing failure; 4. To deal with cross-domain problems, you need to set appropriate CORS headers; 5. To prevent cache interference, you can add a timestamp or set cache:f

How to prevent session hijacking in PHP? How to prevent session hijacking in PHP? Jul 11, 2025 am 03:15 AM

To prevent session hijacking in PHP, the following measures need to be taken: 1. Use HTTPS to encrypt the transmission and set session.cookie_secure=1 in php.ini; 2. Set the security cookie attributes, including httponly, secure and samesite; 3. Call session_regenerate_id(true) when the user logs in or permissions change to change to change the SessionID; 4. Limit the Session life cycle, reasonably configure gc_maxlifetime and record the user's activity time; 5. Prohibit exposing the SessionID to the URL, and set session.use_only

How to URL encode a string in PHP with urlencode How to URL encode a string in PHP with urlencode Jul 11, 2025 am 03:22 AM

The urlencode() function is used to encode strings into URL-safe formats, where non-alphanumeric characters (except -, _, and .) are replaced with a percent sign followed by a two-digit hexadecimal number. For example, spaces are converted to signs, exclamation marks are converted to!, and Chinese characters are converted to their UTF-8 encoding form. When using, only the parameter values ??should be encoded, not the entire URL, to avoid damaging the URL structure. For other parts of the URL, such as path segments, the rawurlencode() function should be used, which converts the space to . When processing array parameters, you can use http_build_query() to automatically encode, or manually call urlencode() on each value to ensure safe transfer of data. just

How to access a character in a string by index in PHP How to access a character in a string by index in PHP Jul 12, 2025 am 03:15 AM

In PHP, you can use square brackets or curly braces to obtain string specific index characters, but square brackets are recommended; the index starts from 0, and the access outside the range returns a null value and cannot be assigned a value; mb_substr is required to handle multi-byte characters. For example: $str="hello";echo$str[0]; output h; and Chinese characters such as mb_substr($str,1,1) need to obtain the correct result; in actual applications, the length of the string should be checked before looping, dynamic strings need to be verified for validity, and multilingual projects recommend using multi-byte security functions uniformly.

PHP find the position of the last occurrence of a substring PHP find the position of the last occurrence of a substring Jul 09, 2025 am 02:49 AM

The most direct way to find the last occurrence of a substring in PHP is to use the strrpos() function. 1. Use strrpos() function to directly obtain the index of the last occurrence of the substring in the main string. If it is not found, it returns false. The syntax is strrpos($haystack,$needle,$offset=0). 2. If you need to ignore case, you can use the strripos() function to implement case-insensitive search. 3. For multi-byte characters such as Chinese, the mb_strrpos() function in the mbstring extension should be used to ensure that the character position is returned instead of the byte position. 4. Note that strrpos() returns f

See all articles