Home  >  Article  >  Web Front-end  >  Ajax internal value cannot be called externally

Ajax internal value cannot be called externally

php中世界最好的语言
php中世界最好的语言Original
2018-04-04 13:48:261900browse

This time I will bring you a solution to the problem that the internal value of ajax cannot be called externally. To solve the problem that the internal value of ajax cannot be called externally. What are the precautions? . Here are the actual cases. , let’s take a look.

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

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.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Ajax implements the function of file upload with progress bar effect

How to use readyState and status in Ajax

The above is the detailed content of Ajax internal value cannot be called externally. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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