yosef Posted April 25, 2015 Share Posted April 25, 2015 (edited) 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 April 25, 2015 by yosef Quote Link to comment https://forums.phpfreaks.com/topic/295869-cant-get-data-with-typeget/ Share on other sites More sharing options...
Muddy_Funster Posted April 29, 2015 Share Posted April 29, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/295869-cant-get-data-with-typeget/#findComment-1510271 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.