0

Let's say I need to upload files to a server programmatically using uploading a file programmatically can a server whatever php java or asp.net return me a value when using POST request method instead of GET ?

If not how can I ask the server which files have been uploaded correctly or that uploads have finished ?

I mean if the server is ANOTHER server than mine I can't see how to get the response so can you give some sample code or refer to some urls.

Community
  • 1
  • 1
user310291
  • 36,946
  • 82
  • 271
  • 487
  • By ANOTHER server do you mean - a service hosted by someone else on which you do not have a control? – Ani Jun 16 '12 at 11:11

1 Answers1

2

It can, same way as GET requests e.g. server can answer with JSON format string response which will include uploaded files or it can return full html page, whatever you need.

E.g. if you want to send some data to server using POST method and you want to alert it you can do something like this (jQuery):

$.ajax({
  type: "POST",
  url: "http://localhost/testing.php",
  data: { name: "John Doe" } // sample data sent to server
}).done(function( msg ) {
  alert( "Response data: " + msg );
});

Generally it shouldn't matter if it was GET or POST, response is returned from server, the only thing you need to do is catch it and perform actions based on response content.

Zbigniew
  • 27,184
  • 6
  • 59
  • 66
  • I don't understand: if the server is ANOTHER server than mine I can't see how to get the response. Do you have some code ? – user310291 Jun 16 '12 at 10:59
  • You have posted general question, without code sample and you want code sample, this is not ok, because we don't really know what is not working. But check my edited answer – Zbigniew Jun 16 '12 at 11:08
  • Sorry I'm not really coder, I just need to know what's possible and I can guess by reading code – user310291 Jun 16 '12 at 11:55
  • Will your code with ajax work with cross domain server ? I think has cross domain problem. – user310291 Jun 16 '12 at 11:59
  • Check those: [jquery-ajax-cross-domain](http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain) & [how-do-i-send-a-cross-domain-post-request-via-javascript](http://stackoverflow.com/questions/298745/how-do-i-send-a-cross-domain-post-request-via-javascript), also remember that sometimes response is redirection, so you may not receive expected response string, but insead you can receive redirection response to other page – Zbigniew Jun 16 '12 at 12:01
  • if it is redirection it means I cannot process it further on programmatically ? – user310291 Jun 16 '12 at 12:32
  • No, it means that you should be redirected to other page to get answer, in this case browser would redirect out to other page, read up more about how http works, you can start with this: [Post/Redirect/Get](http://en.wikipedia.org/wiki/Post/Redirect/Get) – Zbigniew Jun 16 '12 at 12:41