我尝试通过ajax将WagonAvaliableResponse对象发送到方法。当我测试此错误时 TypeError:WagonAvaliableResponse不是函数
如何解决这个问题?
var WagonAvaliableResponse = {
UniqId:'',
checksum:'',
FromStation:0,
ToStation:0,
MainUniqId:0.0,
compartmentCapicityField:'',
isCompartmentField:'',
circularNumberSerialField:'',
countingAllField:'',
rateCodeField:0,
airConditioningField:false,
mediaField:false,
timeOfArrivalField:'',
rationCodeField:0,
soldcountingField:0,
ownerField: ''
};
$('#Continue').click(function(e) {
e.preventDefault;
var obj = new WagonAvaliableResponse();
obj.Uniqid = $('#DepartureTrain article.show input[data=UniqId]').val();
obj.mainuniqId = $('input[name=MainUniqId]').val();
$.ajax({
url: '/Train/CheckValidSelection',
data: obj,
type: "POST",
success: function (result) {
alert(result.Message);
},
error: function () {
alert(result.Message);
}
});
});
答案 0 :(得分:0)
使用$.post
代替$.ajax
,您还可以使其更清晰,更具可读性,请参阅下文。
$('#Continue').click(function(e) {
e.preventDefault;
var obj = WagonAvaliableResponse;
obj.Uniqid = $('#DepartureTrain article.showinput[data=UniqId]').val();
obj.mainuniqId = $('input[name=MainUniqId]').val();
$.post('/Train/CheckValidSelection', obj)
.done(function() {
alert( "Success" );
})
.fail(function() {
alert( "error" );
})