English 中文(简体)
XMLHTTPRE RequestST 贾瓦特的JSON的答复?
原标题:XMLHTTPREQUEST response with JSON in Javascript?

我提出了一个问题。 我试图向一个网络服务器XBMC发出一名JSON的请求。 我可以看到,在网上发送了“POST”请求,答复由网络服务器发出,但在 Java文中,我可以把“JSON”数据引向警示。

var xhr_object = null;

   if(window.XMLHttpRequest) // Firefox
      xhr_object = new XMLHttpRequest();
   else if(window.ActiveXObject) // Internet Explorer
      xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
   else { // XMLHttpRequest non supporté par le navigateur
      alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
      return;
   }

   xhr_object.open("POST", "http://"+add+":9000/jsonrpc", false);

   xhr_object.onreadystatechange = function() {
      if(xhr_object.readyState == 4)
      var json = xhr_object.responseText;
         alert(xhr_object.responseType)
         alert("("+json+")");
   }
   xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   var data =  {"jsonrpc": "2.0", "method": "Input.Up", "id": "1"} ;
   xhr_object.send(data);
最佳回答

我建议你采用一些javascript framework,例如j Query。 查阅http://api.jquery.com/jQuery.getJSON/

如果你利用 j子功能,你就不得不写上大片 j。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签