简体   繁体   English

$ .ajax在IE 8中不起作用

[英]$.ajax wont work in IE 8

I have tried to get my page to work in IE but this code does not work, it will not print out "Fooo!" 我试图让我的页面在IE中工作,但是此代码不起作用,它不会打印出“ Foooo!”。 as a Paragraf eg, nothing is shown. 作为Paragraf,例如,未显示任何内容。 It does however do that in FF wihout any hickups; 但是,它确实在FF中完成了所有操作。

 <script>
    $(document).ready(function(){                   
        $.ajax({
            type: "GET",
            url: "foo.xml",
            dataType: "xml",
            success: function(xml)              
            {
                var markup = "<p>Fooo!</p>"         
                $(markup).appendTo(".container");                                                           
            }
        });                                 
    });                     
</script>

If i make the printout without the "$.ajax" it works in IE without any problems. 如果我不使用“ $ .ajax”进行打印,则它可以在IE中正常工作。 Works in IE; 在IE中工作;

 <script>
    $(document).ready(function(){                   
                var markup = "<p>Fooo!</p>"                                     
                $(markup).appendTo(".container");                               
    });                     
</script>

*Edit Im now sure that it does not read the .xml i added the code; *编辑Im现在确保它不会读取我添加的代码.xml;

error: function(r, s, e) 
{            
alert(s);             
alert(e);        
} 

In the "$.ajax" and it resolves to "parseerror" and "undefiend" in IE. 在“ $ .ajax”中,它在IE中解析为“ parseerror”和“ undefiend”。 I have tried with diffrent XMLs that im pretty sure would work, this for example; 我已经尝试过使用不同的XML,例如,我肯定可以使用。

<?xml version="1.0" encoding="ISO-8859-1"?>
<fooo>
</fooo>

*Edit2 I tried loading a xml from the web (http://www.w3schools.com/xml/note.xml), it resulted in that it worked in IE but not in FF (same fault as prev on IE, "parseerror" and "undefined") any idea? * Edit2我尝试从Web(http://www.w3schools.com/xml/note.xml)加载xml,结果导致它可以在IE中工作,但不能在FF中工作(与IE上的错误相同,“ parseerror “和” undefined“)有什么想法吗?

Any suggestion why the $.ajax (xml-read) dont work? 有什么建议为什么$ .ajax(xml-read)不起作用?

Change your error function to see what error is causing the problem: 更改您的错误功能,以查看导致该问题的错误:

error: function(r, s, e) {
            alert(s);
            alert(r);
       }

EDIT: 编辑:

Maybe try to add 'content type': 也许尝试添加“内容类型”:

...
dataType: "xml",
contentType: "application/xml; charset=ISO-8859-1",
...

please try to change <script> 请尝试更改<script>

to

<script type="text/javascript">

also : 还:

 success: function(xml)              
            {
                var markup = "<p>Fooo!</p>"         
                $(markup).appendTo(".container:first");// I dont know how many you have...                                                           
             }

Does this solve your problem? 这样可以解决您的问题吗? http://bugs.jquery.com/ticket/5273 http://bugs.jquery.com/ticket/5273

Also tried to load XML from another page on the internet? 还尝试从Internet上的另一个页面加载XML吗?

I finally got it to work after finding and reading this; 找到并阅读此书后,我终于使它工作了; http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests

So for IE the input needed to be parsed. 因此,对于IE,需要解析输入。

The final code looks like this; 最终代码如下:

        $.ajax({
            url: "fooo.xml",
            dataType: ($.browser.msie) ? "text" : "xml",                            success: function(data)                 
            {

                var xml;
                if (typeof data == "string") 
                {
                    xml = new ActiveXObject("Microsoft.XMLDOM");
                    xml.async = false;
                    xml.loadXML(data);
                } 
                else 
                {
                   xml = data;
                }

Thanks for all your help, really appreciated! 感谢您的所有帮助,非常感谢! :) :)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM