jquery ajax send form.serialize, variable and array all as d
jquery ajax send form.serialize, variable and array all as data
我有下面的jquery AJAX,
var reply_content = $('#summernote_1').code();
$.ajax({
type:"POST",
url: "<?php echo base_url();?>index.php/test/send_reply/"+<?php echo $testinfo->test_id;?>,
data: $("#test_fm").serialize()+'&file=' + file + '&test_subject=<?php echo $testinfo->testsubject;?>' +'&reply_content=' + reply_content,
});
我有文件变量是数组包含如下
array([0]=> a [1]=>b),
这是与我在 AJAX 中传递的其他函数一起返回的,
如何在 AJAX 中传递它?
var reply_content = $('#summernote_1').code();
$.ajax({
type:"POST",
url: "<?php echo base_url();?>index.php/test/send_reply/"+<?php echo $testinfo->test_id;?>,
data: {$("#test_fm").serialize()+'&file=' + file + '&test_subject=<?php echo $testinfo->testsubject;?>' +'&reply_content=' + reply_content},
});
您可以使用serilizeArray()
如果你在php中尝试它,那么你可以这样尝试:
$url = urlencode(serialize($your_array))
在数据中追加$url
data: {$("#test_fm").serialize()+"&file=<?php echo $url; ?>&test_subject=<?php echo $testinfo->testsubject;?>" +"&reply_content=" + reply_content}
并恢复您可以使用的变量
$arrVar = unserialize(urldecode($_POST['file']))
您可以使用
serializeArray()
来创建也可以添加的对象。在可能的情况下将 php 与 js 分开以提高可读性也是一个好主意:
var url = "<?php echo base_url() . 'index.php/test/send_reply/' . $testinfo->test_id;?>";
var test_subject = "<?php echo $testinfo->testsubject;?>";
var data = $("#test_fm").serializeArray();
data.push(
{
file: file,
test_subject: test_subject
}
);
$.ajax({
type:"POST",
url: url,
data: data
});
相关文章:
- Array.map() and D3 selection?
- JavaScript challenge - Sherlock and array
- insertAdjacentHTML and Array variables
- Difference between Array.apply(null, Array(x) ) and Array(x)
- Javascript IF conditions "array === []" and "
- Javascript,table and array.棘手的问题
- Array() and Array.prototype usage
- forEach() and Apply() methods for two dimensional array in J
- Javascript - Reduce and Array
- Regarding Java Map and Array
- Angularjs: Order and Filter by array intersect
- Javascript array and innerHTML
- 2dimensional array and getElementsByName
- bug using EaselJS and array's
- setTimeout and array each
- Python and a JSON Array
- Node.js, express, jade, highcharts and 2D array
- Preg_match_all and javascript array
- jquery and json array
- javascript array and jsf/richfaces