2012-07-17 53 views
0

我需要从javascript中的webservice url获取数据。 I“m到处响应码为200,但不从URL获得任何数据。 以下是代码从webservice获取数据并将其设置为javascript中的变量

var xmlDoc = null; 
url = 'http://localhost:8458/service1.svc/geturl'; 

if (window.XMLHttpRequest) { 
    xmlDoc = new XMLHttpRequest(); //Newer browsers 
} 
else if (window.ActiveXObject) //IE 5, 6 
{ 
    xmlDoc = new ActiveXObject("Microsoft.XMLHTTP"); 
} 

if (xmlDoc) { 

    xmlDoc.onreadystatechange = function() { 
     if (xmlDoc.readyState == 4 && xmlDoc.status === 200) { 
       alert(xmlDoc.responseText); 
      } 

     } 
     xmlDoc.open("GET", url, true); 
     xmlDoc.send(); 

和我写返回字符串

+0

正在返回什么类型的数据的JSON如果你使用类似萤火虫,你可以看到正在返回什么数据,如果任何 – ajtrichards 2012-07-17 06:15:58

+0

这是返回的数据是不是JSON格式它只是返回字符串形式的网址 – 2012-07-17 06:19:19

回答

0

我会建议使用jQuery的服务这样的:??。

var request_url = 'http://localhost:8458/service1.svc/geturl'; 

$.ajax({ 
    url: request_url, 
    type: "POST", 
    dataType: "html", 
    success: function(response){ 
    // Do something with your response here 
    alert(response); 
    } 
}); 
+0

对不起,但上面的代码不给我任何回应 – 2012-07-17 06:51:51

+0

你有没有包含jQuery库?在localhost地址肯定有东西吗? – ajtrichards 2012-07-17 07:46:37

相关问题