views:

26

answers:

2
<script>
  function jsonfunc(){
   var data ="publick="+document.getElementById("publickeyval").value+"&privatek="+document.getElementById("privatekeyval").value;

   var url="http://www.remoteapiserver.com/example_api/example_adcpatchaapi.php?"+data;
   alert(url);
  var my_JSON_object = {}; 
var http_request = new XMLHttpRequest();
http_request.open( "GET", url, true );
http_request.onreadystatechange = function () {
  if (http_request.readyState == 4){
      alert(http_request.responseText+"#"); // showing only # //
       my_JSON_object = JSON.parse( http_request.responseText );
  }
};
http_request.send(null);


  }
  </script>

I was as asked my question as per comment i read Json and writing above code in my php page.But still this is giving problem.I am not getting fetched dada from remote server.I am getting only "#" in alert box.

+1  A: 

I highly recommend a JavaScript Framework like jQuery for this kind of stuff. It definitely makes this a lot easier. jQuery lets you do cross-domain requests, if you use JSONP (take a look at the docs). The code would look something like this:

$.getJSON(yourUrlGoesHere, function(data) { // ready callback
    // data is an object; no need to parse it manually.
});
elusive
+1  A: 

Sometimes it't better use some library: JQuery or Moootools: http://mootools.net/docs/core/Request/Request.JSON

Implement this in native JS is difficulty if we want use it in all browsers ;)

smialy