0

I have following code in my send.js:

 function send_upload_file(){
        var FD = new FormData();
       FD.append( $this.name, $this.value);
        $.ajax({
            url: 'upload',
            type: 'POST',
            processData: false,
            contentType: false,
            cache: false,
            data: FD,

            success: function (data) { 
            console.log('ok');
            },
            error: function () {
                alert("ERROR in upload");
            }
        });
    }

Can I put two links inside url:? (e.g url: 'upload, send')

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
phpdev
  • 511
  • 4
  • 22
  • Have you tried it? Did it work? No? Did you find any docs that say it _could_ work? What would you expect the browser to do? Load both urls simultaniously, one after each other? – Jeff Dec 21 '16 at 12:05
  • you can of course start another ajax in one of the callbacks (success, error) – Jeff Dec 21 '16 at 12:06
  • No you can't do that. What you want to achieve? – GeekAb Dec 21 '16 at 12:07
  • No but you could write one script on the server called `upload_send` and then inside that controller do both functions – RiggsFolly Dec 21 '16 at 12:17
  • as many have said, no you can't do that, i'd suggest making a question oriented towards achieving your actual goal, since it's not clear what you expect/want this code to do. – Brian H. Dec 21 '16 at 12:19

2 Answers2

3

No. If you wanna send two AJAX requests, you need to do it twice. But the shorthand for this would be:

var success = function () {
  console.log("OK");
};
$.post("upload", FD, success);
$.post("send", FD, success);

The above works asynchronously. If you want to do it synchronously, you need to do:

$.post("upload", FD, function () {
  console.log("OK");
  $.post("send", FD, function () {
    console.log("Sent");
  });
});
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
0

No you can't but try ajax after the first one success

$.ajax({
        url: 'upload',
        success: function (data) { 
               $.ajax({
                      url: 'send',
                   });
            },
            error: function () {
                alert("ERROR in upload");
            }
        });
Sanooj T
  • 1,317
  • 1
  • 14
  • 25