Reputation: 1177
I really have no idea whats wrong with the following code . I am not getting any response in the status ...
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js">
</script>
<input type="text" name="UserName" id="UserName" />
<div id="divStatus"></div>
<script type="text/javascript">
$("#UserName").keyup(function() {
var name = $("#UserName").val();
var status = $("#divStatus");
var user = $.trim(name);
if (user.length > 3) {
status.html("Checking....")
$.getJSON("http://192.168.0.14/openids/api/json/user/username/availability/check/", {
username: name,
}, function(data) {
status.html("got")
});
} else {
status.html("Min 3 letters ");
}
});
</script>
The json response is as follows :
{"status": "Error", "message": "A user with this username already exists."}
Upvotes: 0
Views: 1460
Reputation:
Quoting the documentation:
If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request is treated as JSONP instead. See the discussion of the jsonp data type in $.ajax() for more details.
Since you're making a cross domain request, you probably want to use JSONP. To do this, add a callback
parameter at the end of your querystring:
$.getJSON("http://192.168.0.14/openids/api/json/user/username/availability/check/?callback=", {
username: name,
}, function(data) {
status.html("got")
});
Upvotes: 3
Reputation: 9777
I think what you're running into is that the call is returning an error status but the .getJSON api only gives you the option for a success handler.
What you're going to need to do is look at the .ajax API, which allows you to add an error handler. The .getJSON API shows what it is shorthand for. Look at the .ajax API for all of the options you can pass in addition.
EDIT I didn't notice that this never got to the handler because this was a CORS type request.
Upvotes: 1
Reputation: 66693
Ok, so cross-domain ajax security issue is the trouble. Your calling script and target script should be in the same domain for it to work without additional effort. If you open your browser's error console you should be able to see a security exception there.
Unless you've explicitly set it up to support requests from other hosts.
Check these answers:
How to enable cross-domain request on the server?
Upvotes: 1