简体   繁体   English

我无法在AJAX上加载数据

[英]I can not load data on AJAX

I have an old script which is loading IP from xml file. 我有一个旧脚本正在从xml文件加载IP。 Everything was working fine half year ago on that script. 半年前,该脚本一切正常。 Now i wanted to use that again and it is not working. 现在我想再次使用它,它不起作用。 I don't know what happened. 我不知道发生了什么 Is there something changed on browser or... ? 浏览器或...有什么改变吗? Here is the Javascript 这是Javascript

                    $.ajax({
                        var host;
                        type: "GET",
                        url: "config/config3.xml",
                        async : false,
                        dataType: "xml",
                        success: function(xml) {

                            $(xml).find('config').each(function () {
                                host = $(this).find('ip').text();
                                alert(host);
                            });

                        },
                        error: function(xml) {
                            alert("No XML file");
                        }
                    });  

And XML called config3.xml 和XML称为config3.xml

<config><ip>192.168.0.102</ip></config>

It is not working at all. 它根本不起作用。 Nothing happened. 没啥事儿。 No errors. 没有错误。 Just nothing. 没什么。 Please help 请帮忙

The problem might lie in the fact that you have an improperly formed object. 问题可能在于您的对象的格式不正确。

Remove var host; 删除var host;

HTML 的HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script>
    $.ajax({
        type: "GET",
        url: "config/config3.xml",
        async : false,
        dataType: "xml",
        success: function(xml) {
            console.log('xml success', xml);
            var host;
            $(xml).find('config').each(function () {
                host = $(this).find('ip').text();
                alert(host);
            });

        },
        error: function(xml) {
            alert("No XML file");
        }
    });
</script>

try this: 尝试这个:

  $.ajax({ type: "GET", url: "config/config3.xml", async : false, dataType: "xml", success: function(xml) { var xmlDoc = $.parseXML(xml) xmlDoc.find('config').each(function () { host = $(this).find('ip').text(); alert(host); }); }, error: function(xml) { alert("No XML file"); } }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以通过AJAX从外部页面加载数据吗? - Can I load data from an external page via AJAX? 如何将数据从 ajax 加载到 Chosen jquery? - How can i load data from ajax to Chosen jquery? 如何在后台加载AJAX数据,而不会影响性能? - How can I load AJAX data in the background, without a performance impact? 我如何使用Ajax和Jquery将数据加载到div中,然后插入表单数据并将数据重新加载到div中? - How can I use Ajax and Jquery to load data into a div then, insert form data and reload the data into the div? 我想将ajax响应数据加载到下拉列表中 - I want to load ajax response data into dropdown 我可以在.ajax()调用中加载2个xml文档吗? - Can I load 2 xml doc in an .ajax() call 我可以使用ajax从数据库中加载数据,并以模态包括ckeditor的形式显示,但是我无法编辑/保存这些数据。 我用了Codeigniter 3 - I can load data from database with ajax and show in modal include ckeditor but i can't edit/save those data. I used Codeigniter 3 用ajax加载数据不正确 - load data with ajax not correctly 无法使用ajax调用从服务器加载数据 - Can't load data from the server using ajax call 无法在树形视图插件中从服务器加载AJAX数据 - Can not load AJAX data from the server in tree view plugin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM