jQuery AJAX在GET请求上返回XML已完成 [英] JQuery AJAX return XML on GET request complete

查看:183
本文介绍了jQuery AJAX在GET请求上返回XML已完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

成功返回我的XML文件(或对象)后,我需要执行代码.之前,也没有反复; 之后一次,文件被退回.

I need to execute code once my XML file (or object) has been returned successfully. Not before, and not repeatedly; just one time after the file has been returned.

我的代码已经完成了我要完成的工作吗?似乎在IE中失败了几次,我需要确保它的可靠性.

Does my code already do what I am trying to accomplish? It seems to have failed a couple of times in IE and I need to be sure that it is reliable.

$(document).ready(function(){
    (function GetFile(){
        $.ajax({
          type: "GET",
          url: "Produce.xml",
          dataType: "xml",
          cache: false,
          success: function(result) {
                alert("XML File is loaded!");
                alert(result);
                },      
            async: true
          });
    })();
});

我知道可以检查和验证onerror代码和readystatechange值...在轮询服务器以获取XML文件时,是否应该检查这些值?

I know that there are onerror codes and readystatechange values that can be checked and verified... Should I be checking these values while polling the server for the XML file?

推荐答案

async: true

此外,如果您不打算再次调用,则GetFile函数将立即执行,否则最好使用匿名或一起删除该函数

Also, your GetFile function will execute immediately if you're not planning on calling again then might as well go with anonymous or remove that function all together

$(document).ready(function(){
        $.ajax({
          type: "GET",
          url: "Produce.xml",
          dataType: "xml",
          cache: false,
          success: function(result) {
                alert("XML File is loaded!");
                alert(result);
                },      
            async: true
          });
});

这篇关于jQuery AJAX在GET请求上返回XML已完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆