Home > Web Front-end > JS Tutorial > Reasons and solutions why ajax internal values ​​cannot be called externally

Reasons and solutions why ajax internal values ​​cannot be called externally

亚连
Release: 2018-05-23 17:18:26
Original
2055 people have browsed it

Below I will bring you an article on the reasons and solutions for why ajax internal values ​​cannot be called externally. Let me share it with you now and give it as a reference for everyone.

The reason why the internal value of ajax cannot be called externally and the solution

var id=‘123';
$.ajax({   
        url:'http://www.xxx.com/ajax',   
        type:'post',
        dataType: "json",
        data:{wurl:w_url,murl:m_url}, 
        async : turn, 
        error:function(){  
        },
        success:function(data){
          var id= data[‘id'];
          console.log(id) // 这里出来的是100
   
         }
      })
      console.log(id); //这里出来的是123
Copy after login

The problem lies in the async synchronization step option of ajax. If async: false, means running in synchronous mode, and then execute the following statement after ajax loading is completed. If async: turn, it means asynchronous execution. If ajax does not reach the value, it will have the opportunity to receive the next statement of ajax.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Comprehensive analysis of Ajax comprehensive applications

How to use Nginx reverse proxy to avoid ajax cross-domain requests

In-depth analysis of Nginx implementation of AJAX cross-domain request issues

The above is the detailed content of Reasons and solutions why ajax internal values ​​cannot be called externally. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template