2012-01-05 60 views
0

我有以下代码试图从web加载XML文件。

$.ajax({ 
    url: 'http://www.kumarchetan.com/blog/feed/', 
    success: function(xhrresponse){ 
     $('#container').html(xhrresponse);//does nothing 
     navigator.notification.alert("Data Loaded: " + typeof xhrresponse);//tells me its an object 
    }, 
    error: function(){ 
     navigator.notification.alert("PC LOAD LETTER"); 
    } 
}); 

我试过使用$.get()以及它没有工作。我将此代码替换为以下代码

$('#hiddenContainer').load('http://www.kumarchetan.com/blog/feed/'); 

它的工作原理类似于魅力。托管XML文件的服务器在服务器端没有特殊的事情。

编辑
我尝试添加dataType:'xml'为好,这是行不通的。

+0

您正在开发适用于iOS的应用程序吗? – Andrei 2012-01-05 10:15:01

+0

@Andrei,它的Android版。 – Kumar 2012-01-05 10:22:33

回答

0

意识到,我不得不加5秒的超时之前,我开始使用XML响应。

0

您是否尝试过明确设置数据类型?像:

$.ajax({ 
    url: 'http://www.kumarchetan.com/blog/feed/', 
    success: function(xhrresponse){ 
     $('#container').html(xhrresponse);//does nothing 
     navigator.notification.alert("Data Loaded: " + typeof xhrresponse);//tells me its an object 
    }, 
    error: function(){ 
     navigator.notification.alert("PC LOAD LETTER"); 
    }, 
    dataType: 'xml' 
}); 

或者

$.get('http://www.kumarchetan.com/blog/feed/', function(xhrresponse){ 
    $('#container').html(xhrresponse);//does nothing 
    navigator.notification.alert("Data Loaded: " + typeof xhrresponse);//tells me its an object 
}, 'xml'); 
+0

我忘了提及我也加了'dataType'参数,但它不起作用,我会更新这个问题。 – Kumar 2012-01-05 05:09:47

相关问题