I’m writing a piece of code that checks if what you write in a text-box is a valid username, using jQuery and Ajax I then see if this page exists – http://api.twitter.com/1/users/show/value.xml – if it doesn’t exist i write something like “This twitter account does not exist”.
This is the code:
function checkname (name) {
$.ajax({
url: "http://api.twitter.com/1/users/show/" + name + ".xml",
statusCode: {
404: function() {
$("#divOfInterest").html("Sorry, " + name + " is not a valid twitter account");}
}
});
}
But it doesn’t work and i don’t really know why, here’s my fiddle, so you can see yourself. Any help is appreciated.
You can create a php page on your server and make the request to the api using their method.
https://dev.twitter.com/docs/api/1/get/users/lookup
PHP page: (check.php)
Then call it from ajax
To make a request to the same page modify it this way.
put php script at the top of your document before everything else.
in the javascript add new variable
ajax=1and the url