0

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

5
  • What response does the server give you? I can see you're using JSONP so it's probably not a cross domain issue. Commented Oct 15, 2012 at 10:55
  • Maybe a same origin policy matter? Check the console messages in the browser. Commented Oct 15, 2012 at 11:00
  • what language are you using server side? Commented Oct 15, 2012 at 11:08
  • might be worth looking at this: stackoverflow.com/questions/2067472/please-explain-jsonp Commented Oct 15, 2012 at 11:13
  • You are working with json.php, its response has changed. Commented Oct 15, 2012 at 11:14

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Where should i enter these details, I am already using callback
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.