user2082159
user2082159

Reputation: 11

Jquery AJAX call for XML file working in FF but NOT in IE and Chrome?

Recently I am working with a bug regarding XML file retrieve in "IE and Chrome". Well, I used Ajax GET call for the same and it works fine in FF but does not work in IE and Chrome. Lets see what exactly happens with my code:

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

<folder>
    <title>Inbox</title>
    <subject>LinkedIn Connection111 </subject>
    <from>[email protected] </from>
    <to> [email protected] </to>
</folder>

<folder>
    <title>Outbox</title>
    <subject>LinkedIn Connection111 </subject>
    <from>[email protected] </from>
    <to> [email protected] </to>
</folder>

<folder>
    <title>Sent</title>
    <subject>LinkedIn Connection111 </subject>
    <from>[email protected] </from>
    <to> [email protected] </to>
</folder>

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The above is the XML file.

Now, when I am trying to alert the data it works in FF but not with IE and Chrome.

Following is the code for the HTML File:

<!DOCTYPE html>   
<html lang="en">   
<head>   

<meta charset="utf-8">   
<title>Satya's Twitter Bootstrap Modals</title>   
<meta name="description" content="Creating Modal Window with Twitter Bootstrap">    
<script src="jquery-2.0.0.min.js"></script>  
</head>  
<body>  
<script> 
var searchFolder = 0;
//var fromVal;
$(document).ready(function(){
        //var i;
        $.ajax({
            type: "GET",
            url: "newXml.xml",
            dataType: "xml",
            success: function(xml){
            //alert("DSSS");
            var searchFolder = $(xml).find("folder");
            //alert("SDR");
            $(searchFolder).each(function(){
            var titlee = $(this).find('title').text();
            //alert("SSS");
            alert(titlee);
            });
            },
            error: function() {
            alert("An error occurred while processing XML file.");
            }
            });
            });
</script>

Hello
</body>
</html>

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Now, the Program runs fine in FireFox and alerts the value of "title" everytime BUT the same does not work in IE and Chrome.

Please suggest me the exact problem with the code. Waiting for your response.

Thanks

Upvotes: 1

Views: 615

Answers (1)

caoyue
caoyue

Reputation: 11

Because your xml format is wrong. The format should be:

<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
    <folder>
        <title>Inbox</title>
        <subject>LinkedIn Connection111 </subject>
        <from>[email protected] </from>
        <to> [email protected] </to>
    </folder>

    <folder>
        <title>Outbox</title>
        <subject>LinkedIn Connection111 </subject>
        <from>[email protected] </from>
        <to> [email protected] </to>
    </folder>

    <folder>
        <title>Sent</title>
        <subject>LinkedIn Connection111 </subject>
        <from>[email protected] </from>
        <to> [email protected] </to>
    </folder>
</root>

Upvotes: 1

Related Questions