h_h
h_h

Reputation: 1231

jquery json parsing from remote host

I am trying to get json data from a remote host with the following code. But failing, I am using jquery get json

my code

<script type="text/javascript" language="javascript">

$(document).ready(function() {
  $("#driver").click(function(event){
      $.getJSON('http://108.167.132.194/~softnet/json.php?callback=?', function(jd) {
         $('#stage').html('<p> Name: ' + jd.name + '</p>');
         $('#stage').append('<p>Password : ' + jd.password+ '</p>');

      });
  });
});

</script>

When i try to get data from localhost it works perfectly

Upvotes: 0

Views: 371

Answers (2)

user1726343
user1726343

Reputation:

Your server needs to wrap the response in a callback so the browser doesn't instantly evaluate it. The callback parameter should then be set to the name of the callback that is returned.

Upvotes: 0

Subir Kumar Sao
Subir Kumar Sao

Reputation: 8401

You should look into cross-domain ajax call. What you are trying to do will not work directly. You will either have to use JSONP or add the ips/hosts to allowed domain list.

What I can see from your client side code is that you are using JSONP but your server side does not support it. You need to implement it on also on the server side to support JSNOP.

Upvotes: 1

Related Questions