0

So my script right now is:

$(document).ready(function() {
  $("#submit").bind('click', function() {
    var username = $("#username").val();
    $.ajax({
      type: "GET",
      url: 'http://www.roblox.com/UserCheck/DoesUsernameExist?username=' + username,
      data: {
        q: username
      },
      async: true,
      dataType: 'jsonp', //you may use jsonp for cross origin request
      crossDomain: true,
      success: function(data, status, xhr) {
        alert(xhr.getResponseHeader('Location'));
      }
    });

  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="username" type="text" name="" value="" placeholder="Enter your idiom here">
<br>
<button id="submit" type="">Submit</button>

How do I make it so I can make this script work with the +username? I need help on fixing this, this isn't my original code but I am just tinkering with it. I am new to stuff like JS, JSON, etc.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Is expected result to set `username` at `input` element `change` https://developer.mozilla.org/en-US/docs/Web/Events/change event ? – guest271314 Nov 06 '15 at 00:09
  • I don't see a question anywhere. – Barmar Nov 06 '15 at 00:13
  • As far as I can tell, the Roblox API doesn't implement JSONP. – Barmar Nov 06 '15 at 00:15
  • when i tried another script, it wasn't with jsonp and it hard a CORS error. I looked up on how I can fix it and it said use jsonp with cross domain. Also go to the link 'http://www.roblox.com/UserCheck/DoesUsernameExist?username=Shedletsky ' that's json right? and also how is json different from jsonp – Dominus Dominius Nov 06 '15 at 00:17
  • http://stackoverflow.com/questions/2887209/what-are-the-differences-between-json-and-jsonp?s=1|4.6480 – Barmar Nov 06 '15 at 00:21
  • JSONP only works if the API supports it. Since this API doesn't, you need to write a script on your own server that calls the API. – Barmar Nov 06 '15 at 00:22
  • How do you call an API?? – Dominus Dominius Nov 06 '15 at 00:24
  • @Barmar also when i run the code it has an error stating "SyntaxError: missing ; before statement" – Dominus Dominius Nov 06 '15 at 00:30
  • The way that JSONP works is that the it creates ``. The server is supposed to return a script that contains `;func(jsonobject);`. If it just returns the JSON object, that's not a valid script, and you get an error. – Barmar Nov 06 '15 at 00:33
  • @Barmar ohhh i understand. :/ i'll just give up on this project because i do not know what i am doing :| – Dominus Dominius Nov 06 '15 at 00:37

0 Answers0