-5

I would like to know how to pass array of datas to ajax call how to load modal until the data received in success in ajax. Please check the below code and help.thanks

static(){
    var src = "SG";
    var tar = "TH";
    var samount = 1000;
    var sourceccy = "SGD";
    var targetccy = "THB";
    var providers = ["trans","fund"];
    $.ajax({
      url: "/en/send-money-from-" + sourcecn + "-to-" + targetcn,
      method: 'get',
      data: {
        srccn: src,
        tarcn: tar,
        source: sourceccy,
        target: targetccy,
        provider: providers //pass array in ajax call
      },
      success: function (data) {
        $('body').html(data);
      }
    });
  }

mia
  • 235
  • 1
  • 4
  • 17
  • 2
    Possible duplicate of [Pass array to ajax request in $.ajax()](https://stackoverflow.com/questions/8890524/pass-array-to-ajax-request-in-ajax) – Jonast92 May 08 '19 at 15:11
  • Possible duplicate of [Serializing to JSON in jQuery](https://stackoverflow.com/questions/191881/serializing-to-json-in-jquery) – Woodrow May 08 '19 at 15:11
  • 1
    any chance you could restrict it to a single question (like what modal are you talking about, since you do a `console.log` you know where it will end up :) – Icepickle May 08 '19 at 15:15
  • @Icepickle thanks for reply, updated code – mia May 08 '19 at 15:17

1 Answers1

0

Create an object like:

var obj = {
        "srccn": src,
        "tarcn": tar,
        "source": sourceccy,
        "target": targetccy,
        "provider": providers
      }

then in data use data: JSON.stringify(obj);

Carlos Alves Jorge
  • 1,919
  • 1
  • 13
  • 29