Link to home
Start Free TrialLog in
Avatar of karthik80c
karthik80cFlag for United States of America

asked on

How to pass ajax request from an array collection Js

Hi Experts,

This is my html
<input type ='checkbox' data-param=1553066000000681004>

Open in new window

. when  check box is checked i need to get the attribute value and pass it to ajax request . but in my page i have multiple check box like this and i get the value . but i cant pass this as ajax request bcoz its a array and i go for each function in jquery but it wont work . Please Take a look at my code

$boxes = $('input[type=checkbox]:checked');
if ($boxes.length == 1) {

$id = $(this).attr("data-param");
//do something
}else{
$boxes.each(function () {
$newid=[];
$newid=$(this).attr("data-param")+' ; ' ;

});
 $.post("contacts.aspx?id="+newid,
 function(data, status){
        alert(data);
    });
}

Open in new window

Avatar of Vimal DM
Vimal DM
Flag of India image

Hi,

Using JSON.stringify(ArrayVariable)  function convert the array into JSON string format and pass the JSON through ajax request.

After receiving the JSON values in the target page using PHP built in function "json_decode($string, true);" you can parse it.

Note: it suites for all the technology...
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial