Sending Javascript Object to PHP via Ajax

前端 未结 3 502
离开以前
离开以前 2020-12-06 00:01

I\'m learning Ajax by failure and have hit a wall:

I have an array (if it matters, the array is storing number id\'s based on what checkboxes the user checks) that i

3条回答
  •  死守一世寂寞
    2020-12-06 00:36

    First off, yes, do not write ajax by hand. You are unlikely to produce something that truly works on all browsers.

    The best approach to your actual problem would be to submit your array as cgi parameters.

    If the checkboxes are in a form, you need to do very little - simply submit the form,

     
    $.post("test.php", $("#testform").serialize());

    See http://api.jquery.com/jQuery.post/ for more details on how to do that. Your list will turn up as an array in PHP.

    Or to augment your own example with something very simple, do this:

      url = url + '?checkboxes=' + checkboxes.join(',');
    

    Now just split it inside PHP and you've got it back!

提交回复
热议问题