weixin_33725272 2016-02-03 22:11 采纳率: 0%
浏览 24

Ajax Call的结果[重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call" dir="ltr">How do I return the response from an asynchronous call?</a>
                            <span class="question-originals-answer-count">
                                (38 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2016-02-04 03:11:45Z" class="relativetime">4 years ago</span>.</div>
        </div>
    </aside>

I have an ajax call and I want to use result of this ajax on another page.

//This is main.js file

function myFun(){
    var my_user = "Stas";
    var itemsUrl = "myxmlwithusers";
    var user_found = false;
    $.ajax({
         url: itemsUrl,
         method: "GET",
         headers: { "Accept": "application/json; odata=verbose" },
         cache: false,
         async: false,
         dataType: "text",
         success: function(data){
            var jsonObject = JSON.parse(data);
            results = jsonObject.d.results;
            $(results).each(function(){ 
                if($(this)[0].user == my_user){
                     user_found = true;
                }
            });
         },
         error:function () {
              console.log("Error");
          }
        }
    );
}

// This is execute.js file

myFun();
if (user_found == true){cool}

I need true or false for // user_found. Let say I will put in the file execute.js my function myFun() and in main.js my user is fetch with "$(this)[0].user" and I need to receive "true" in execute.js

Thanks!

</div>
  • 写回答

3条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 c++字符串分割问题
      • ¥15 关于#sql#的问题:没有用命令关闭cdc,手动把系统表开启的cdc右键删除了
      • ¥15 android freedom
      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题
      • ¥15 win11如何运行geoserver
      • ¥15 审稿意见请教-用ERNIE进行小样本分类的对比实验问题
      • ¥15 gem5搭建arm v8