Jump to content

cant get data with type:GET


yosef

Recommended Posts

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

Edited by yosef
Link to comment
Share on other sites

you should start using console.log() to catch error, rather than alerts, you can access it using firebug in firefox, or in the developer tools in chrome (and probably some way in gimpernet explortr/spartan too). That said, you need to look into the requirements of file upload, either to your own server or to a remote one. see here for the html form requirements.  The other thing is you want to be using POST in your AJAX as you are actually posting the file to the uploads.ru site.  you also need to set the AJAX headers to the correct data type and then just hadle the display of the link in the success callback.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.