0

I'm using .ajaxForm to submit both form data and image files. I have multiple asynchronous calls being made using the same ajaxForm code (most of which do not handle images).

All is fine until ajax encounters an error, at which point I am unable to access any posted data via the error function in order to identify the ajax call that threw the error (in order to correctly handle it with my code).

I was using the this.data solution suggested by Hammersholt in this thread which works fine when a fileInput is not used, but fails to retrieve data when a file is selected.

A solution that works using ajaxForm for both data and files would be preferred.

Many thanks for any help with this,

Antony

Community
  • 1
  • 1

1 Answers1

0

As you can see the scope of imp_wl_data is global in this case

var imp_wl_data = []
 var imp_wl_ajaxquery = $.ajax(
  {
    url: 'https://myurl',

    async: false,
    success: function(imp_wl_data_res)
    {
      imp_wl_data = JSON.parse(imp_wl_data_res);
    },
  error: function(jqXHR, exception) {
    {
    alert(imp_wl_data);      
    },

  });

Check this

var orderinfo = {
      'ordersplitjson': JSON.stringify(ordersplitjson),
        'customer_id': cust_id,
        'homedelivery': homedelivery,
        'seatnum': seatnum,
        'locationname': location_nam,
        'rownum': rownum
    };
    var json_data = JSON.stringify(orderinfo);
    var ajaxcallquery = $.ajax({
        type: 'POST',
        dataType: 'json',
        data: json_data,
        cache: false,
        async: true,
        contentType: "application/json; charset=utf-8",
        url: url + '/orderinsertservice',
        timeout: 10000,
        success: function(response) {


        },
       error: function(jqXHR, exception) {


        }
    });
Pawan
  • 31,545
  • 102
  • 256
  • 434