我正在使用表单,我想通过 jQuery .serialize() 函数发布所有字段,但是当我警告我的序列化对象时,它只会警告键,而不会显示键的值。
这是我的 Angular 脚本。
app.controller('myForm',function($http,$scope){
$scope.mydata=$('#myform').serialize();
$scope.saveCashbook=function()
{
alert(this.mydata);
$http({
method: "POST",
url: 'cashbook/save_cash_entry',
data: this.mydata,
}).success(function (data) {
if (data.status == 'success') {
alert('all okay');
} else {
alert(data.msg)
}
});
}
});
它在 jquery 中正常工作的地方
$('#submit').click(function(event) {
var mydata=$('#myform').serialize();
alert(mydata);
});
请帮我找出错误所在。
最佳答案
我已经使用以下代码完成了...对我来说序列化工作主要是提供信息的标题 headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
app.controller('myForm',function($http,$scope){
$scope.saveCashbook=function()
{
$http({
method: "POST",
url: 'cashbook/save_cash_entry',
data: $('#supplier_form').serialize(),
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
}).success(function (data) {
if (data.status == 'success') {
alert('all okay');
} else {
alert(data)
}
});
}
});
关于jQuery .serialize() 在 Angular 中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34119340/