Users are able to enter a URL into a text field, I would like to add a jQuery based feature that would be able to check if a page at least exists so that I could warn a user if they may have accidentally entered an incorrect URL, before they hit "save"
Currently I am trying to use the following code, though it seems to always return the "Error: Does not exist" message:
$('#Inventory_edocsUrl').blur(function(){
$.ajax({
url:$('#Inventory_edocsUrl').val(),
type:'GET',
success: function()
{
console.log('Success, file exists!');
},
error: function()
{
console.log('ERROR:Does not exist');
}
});
});
I tested with http://google.com
as a test url in the text field and it still returned the error. Upon switching the url to google.com
(not http), I got the same error message along with another error message:
GET http://localhost/inventory/web/inventory/google.com 404 (Not Found)
It makes sense that this second version does not work as there is no http:// and therefore the error should be returned, but I don't see why the first correct url is returning the programmed error message, but is actually returning no console errors like the second trial.
Is there something I am doing wrong?