user3805367
user3805367

Reputation: 49

Passing an javascript array to an struts action class using ajax request in jquery

I have an array ids_arr which is initialized with some values. I have to pass this array and retrieve it in an Action class.

Following is My code:

Script:

$.get('deleteProduct',
  {

    arr_ids_fm_ajax : ids_arr
  },
  function(jsonResponse){
    alert(jsonResponse.msg);
  }
    );

}

Action class:

public class ProductDetails extends ActionSupport {

    int arr_ids_fm_ajax[];

    public int[] getArr_ids_fm_ajax() {
        return arr_ids_fm_ajax;
    }

    public void setArr_ids_fm_ajax(int[] arr_ids_fm_ajax) {
        this.arr_ids_fm_ajax = arr_ids_fm_ajax;
    }

    public String deleteProduct() {
        System.out.println(arr_ids_fm_ajax[0]); // here i want the values of my
        // passed array from ajax.

        return "success";
    }
}

Error at console :

Parameter [arr_ids_fm_ajax[]] didn't match acceptedPattern pattern!

Please provide a solution. Thanks for the reply in advance.

Upvotes: 1

Views: 1468

Answers (1)

user3805367
user3805367

Reputation: 49

Passing array like this solved the problem.

data: $.param({
        arr_ids_fm_ajax: ids_arr
      }, true)

Upvotes: 1

Related Questions