-3

I have a form that would pass ids of some items to ajax and i need to update all the rows with those arrays with the updated datas. I have to use ajax to accomplish this. The ids are generated through mysql queries and I passed it to an array. So it is already an array and how do i change to javascript-processable(if that's a word) data and change it back to php array. Here's my code this is how to make the array

foreach($items as $item){
    $item_arr[]=$item['id']
}

and I pass the array to an input field to fetch to ajax

<input type="hidden" id="myid" value="<?php echo json_encode($item_arr); ?>"/>

and

    $myid=$("#myid").val();
    $.ajax({
    url:"myurl.php",
    data:{myid:myid},
})

this is returning I don't know what!!Please help this is my first try with this kind of conversion of array..Please bear with me

Ibrahim Azhar Armar
  • 25,288
  • 35
  • 131
  • 207
Narendra Chitrakar
  • 185
  • 1
  • 2
  • 13
  • Possible duplicate http://stackoverflow.com/questions/5571646/how-to-pass-a-javascript-array-via-jquery-post-so-that-all-its-contents-are-acce – redslazer May 31 '12 at 07:09
  • 3
    It's generally expected that you show some effort before asking questions. – emilan May 31 '12 at 07:11

1 Answers1

0

If data in the "myid" field is already a json string, just pass it directly via ajax, with:

var myid=$("#myid").val();
$.ajax({
    url:"myurl.php",
    data:myid
});
CoursesWeb
  • 4,179
  • 3
  • 21
  • 27