0

I'm trying to get game server data from my other host because my main host doesn't allow server querying. But i'm having problems with json right now..

My code:

    <script type='text/javascript'>
    $(document).ready(function(){
        $("input.senddata").click(function() {
            var ipForm = $('input[name="ip_submit"]').val();
            var gameForm = $( 'select[name="game_submit"]' ).val()
            $.getJSON("http://gamepwn.net/serversdotee/add-server.php?json=true",
              {
                ip: ipForm,
                game: gameForm
              },
              function(data) {
                $('.result').html(data);
              });
        });
    });
</script>

The data that i want to get back is a simple text for example "Server has been queried"..

3
  • Check in Firefox's Firebug plugin, or in Chrome's Developer tools to see if you're getting any AJAX response back. Commented Jun 26, 2012 at 15:37
  • If you want to do cross-domain requests, you need to use a data type of JSONP. And, if you specify a data type of JSONP, the response needs to be valid JSON. Commented Jun 26, 2012 at 15:38
  • I do get back a response! GET gamepwn.net/serversdotee/… 200 OK 2.07s Commented Jun 26, 2012 at 15:43

1 Answer 1

2

Either your "other server" needs to return proper CORS headers, or you need to move to the JSONP datatype and modify your "other server" so that it properly returns JSONP rather than JSON.

JSONP vs JSON:

JSON: http://gamepwn.net/serversdotee/add-server.php?json=true

{"foo":"bar"}

JSONP: http://gamepwn.net/serversdotee/add-server.php?json=true&callback=??

jQuery_7891469862340189270349182561({"foo":"bar"})

Where jQuery_7891469862340189270349182561 is the value of the callback GET parameter.

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

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.