传递数组到$阿贾克斯Ajax请求() [英] Pass array to ajax request in $.ajax()

查看:116
本文介绍了传递数组到$阿贾克斯Ajax请求()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  

可能重复:
  序列化到JSON在jQuery的

我想送一个数组作为一个Ajax请求:

 信息[0] ='喜';
信息[1] ='你好';

$阿贾克斯({
  键入:POST,
  网址:的index.php
  成功:函数(MSG){
    $('答案')HTML(MSG)。
  }
});
 

我怎样才能做到这一点?

解决方案

 信息= [];
信息[0] ='喜';
信息[1] ='你好';


$阿贾克斯({
   键入:POST,
   数据:{信息:信息},
   网址:的index.php
   成功:函数(MSG){
     $('答案')HTML(MSG)。
   }
});
 

Possible Duplicate:
Serializing to JSON in jQuery

I want to send an array as an Ajax request:

info[0] = 'hi';
info[1] = 'hello';

$.ajax({
  type: "POST",
  url: "index.php",
  success: function(msg){
    $('.answer').html(msg);
  }
});

How can I do this?

解决方案

info = [];
info[0] = 'hi';
info[1] = 'hello';


$.ajax({
   type: "POST",
   data: {info:info},
   url: "index.php",
   success: function(msg){
     $('.answer').html(msg);
   }
});

这篇关于传递数组到$阿贾克斯Ajax请求()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆