我正在尝试从beforeSend
函数中的数据数组中获取值,但是当我尝试在控制台中显示它时,我看到的是undefined
。
我尝试打印$(this)
变量,该变量也返回undefined
。
$("form").submit(function(){
var data = {
"action": $(this).attr("id")
};
data = $(this).serialize() + "&" + $.param(data);
$.ajax({
type: $(this).attr("method"),
dataType: $(this).data("type"),
url: $(this).attr("action"),
data: data,
beforeSend: function(data) {
console.log(data["action"]);
console.log($(this).attr("method"));
}
});
return false;
});
如何在beforeSend
函数
答案 0 :(得分:1)
直接,简单地说:
<?php
if (sizeof($days) > 0) { //If json is not empty
$firstColumn = $days[0] ; //First Column (<thead> values)
?>
<table>
<thead>
<tr>
<?php foreach ($firstColumn AS $k => $v) { ?>
<th><?php echo $v?></th>
<?php } ?>
</tr>
</thead>
<tbody>
<?php
foreach($days as $k => $v) {
if ($k != 0) { ?>
<tr>
<?php
foreach ($v AS $k1 => $v1) { ?>
<td><?php echo $v1 ?></td>
<?php
} ?>
</tr>
<?php
}
} ?>
</tbody>
</table>
<?php
} ?>
。
这是serialize String,然后你可以通过字符串解析/编辑来做任何事情。
例如使用:
this.data
用于显示序列化字符串。