$ .ajax不会在IE 8中运行

时间:2022-03-17 06:50:32

I have tried to get my page to work in IE but this code does not work, it will not print out "Fooo!" as a Paragraf eg, nothing is shown. It does however do that in FF wihout any hickups;

我试图让我的页面在IE中工作,但这段代码不起作用,它不会打印出“Fooo!”作为Paragraf,例如,没有显示任何内容。然而它确实在FF中没有任何hickups;

 <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. Works in IE;

如果我在没有“$ .ajax”的情况下进行打印输出,它可以在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;

*编辑我现在确定它没有读取.xml我添加了代码;

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

In the "$.ajax" and it resolves to "parseerror" and "undefiend" in IE. I have tried with diffrent XMLs that im pretty sure would work, this for example;

在“$ .ajax”中,它解析为IE中的“parseerror”和“undefiend”。我尝试过不同的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我尝试从网上加载一个xml(http://www.w3schools.com/xml/note.xml),结果是它在IE中工作但不在FF中(与IE上的prev相同的错误,“parseerror) “和”未定义“)任何想法?

Any suggestion why the $.ajax (xml-read) dont work?

有什么建议为什么$ .ajax(xml-read)不起作用?

4 个解决方案

#1


1  

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",
...

#2


0  

please try to change <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...                                                           
             }

#3


0  

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?

还试图从互联网上的另一个页面加载XML?

#4


0  

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! :)

感谢您的帮助,非常感谢! :)

#1


1  

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",
...

#2


0  

please try to change <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...                                                           
             }

#3


0  

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?

还试图从互联网上的另一个页面加载XML?

#4


0  

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! :)

感谢您的帮助,非常感谢! :)