开发者

How to post a Array using Jquery

开发者 https://www.devze.com 2022-12-22 04:02 出处:网络
hello frieds this is how i usually post a variable using Jquery.. $.post(\"include/save_legatee.inc.php\", { legatee_name: legatee_name_string,

hello frieds this is how i usually post a variable using Jquery..

$.post("include/save_legatee.inc.php", { legatee_name: legatee_name_string,
                                            legatee_relationship:legatee_relationship_string,                                               
                                                            }, function(response){

                                                                alert(response);

                                                            });

Can anybody explain how to post an 开发者_开发百科array using Jquery..

   var all_legattee_list= new Array();
  all_legattee_list[1]="mohit";
  all_legattee_list[2]="jain";

this is my array... How can post this using jquery???


$.post(
    'include/save_legatee.inc.php', 
    { all_legattee_list: ['mohit', 'jain'] }, 
    function(data) {

    }
);


Post this as a string separated with some delimiter.

use .join() to join the array

var strJoinedArray = all_legattee_list.join(',');

and in your php code split the string using , and retrieve the values.


you have to use all_legattee_list[] as name of your parameter, something like this:

$.post("...", "all_legattee_list[]=mohit&all_legattee_list[]=jain", ...);


For example, like this: Serializing to JSON in jQuery. Of course the server would have to support JSON deserialization, but many server-side languages already do.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号