I'm trying to fire an event on spacebar press if an url is found in the last word typed and kill that event if there is a result so if the user keeps typing... the function doesn't keep on sending requests to the server. I'm tired and hope this makes sense... Basically I'm trying to accomplish what facebook has when you submit a post and enter an url beginning with http://. I've got it working 100% perfect... you can type and type and when an url is entered beginning with http:// it pings the server, grabs meta data, images from page, etc. But when the user keeps typing, the function seems to go for a loop and freezes because it's still trying to find an url?
Heres the code anyhow below:
$(document).keypress(function(e){
$('#example').keyup(function() {
if(e.which == 32) {
var body = $('#example').attr('value');
var body = encodeURIComponent(body);
$.ajax({
type: "GET",
url: "get_url.php",
data: "entry="+body,
cache: false,
success: function(html) {
$("#new_url").html(html);
}
});
return false;
}
});
});
I know it's messy... still learning jQuery!
Thanks for all the help! I would like to scan the textarea input as the user types for an url starting with http://, www, or http:// w w w. using jquery, when found trigger the ajax request and stop the function from looking any further for urls... but am currently using regex in php to find url, fetch data, and return it...