Donnie Walker
asked on
Is there a way to check if a file exists with javascript or jquery?
I've got a form that allows a user to upload a file.
Is there a way to check if that file exists after uploading using javascript or jquery?
Is there a way to check if that file exists after uploading using javascript or jquery?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
when I run this I get nothing:
<script>
$.ajax({
type: 'HEAD',
url: 'http://www.example.com/index.php',
success: function() {
alert('Page found.');
},
error: function() {
alert('Page not found.');
}
});
</script>
<script>
$.ajax({
type: 'HEAD',
url: 'http://www.example.com/index.php',
success: function() {
alert('Page found.');
},
error: function() {
alert('Page not found.');
}
});
</script>
work for me :
found : http://jsfiddle.net/cyVGM/4/
not found : http://jsfiddle.net/cyVGM/
be sure to have jQuery in place
found : http://jsfiddle.net/cyVGM/4/
not found : http://jsfiddle.net/cyVGM/
be sure to have jQuery in place
I can't get that to work on any file that is on another server. It will work for local files but not remote ones.
ASKER
This is what I have and I get nothing:
<html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com /ajax/libs /jquery/1. 7.2/jquery .min.js">< /script>
<script type="text/javascript" src="//ajax.googleapis.com /ajax/libs /jqueryui/ 1.8.22/jqu ery-ui.min .js"></scr ipt>
</head>
<body>
<script>
function fileExists(fileLocation) {
var response = $.ajax({
url: fileLocation,
type: 'HEAD',
async: false
}).status;
alert(response);
}
</script>
<script> fileExists('/Uploads/test. pdf'); </script>
</body>
</html>
<html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com
<script type="text/javascript" src="//ajax.googleapis.com
</head>
<body>
<script>
function fileExists(fileLocation) {
var response = $.ajax({
url: fileLocation,
type: 'HEAD',
async: false
}).status;
alert(response);
}
</script>
<script> fileExists('/Uploads/test.
</body>
</html>
ASKER
maybe that is why mine is not working. Two different servers on the same network.
ASKER