i am trying to upload picture with ajax to a site (uploads.ru) that takes the picture and give you back a new url. i use tag form to submit the file, but i dont want my page to refresh or go to a new site (uploads.ru). the problem: when i use POST, it goes to 'uploads.ru' site and give me the correct result that i want, but when i use GET it gives me result: "bad request"- according to the site, their api works with POST and GET.
thank you for any help.
<html>
<form id="idForm" method="GET" action="http://uploads.ru/api?upload" enctype="multipart/form-data">
<input name="file" type="file">
<input type="submit" name="submit" value="Submit" />
</form>
<script>
$("#idForm").submit(function() {
//e.preventDefault();//use it here to stop default behaviour
alert("hi");
var url = "http://uploads.ru/api?upload";
$.ajax({
type: "GET",
url: url,
data: $("#idForm").serialize(),
success: function(data) {
alert("TEST");
//alert(data.status_txt);
}
});
return false;
});
</script>
</html>
test1.html