因为form提交的时候页面会自动提交到/apply 这个处理页面,返回JSON数据
所以用ajax重定向到/applysuccess
重定向成功了可是数据怎么没提交成功的样子 获取的时候看到都是null
求帮助
//ajax的代码
$.ajax({
type: 'post',
url: '/apply',
async: true,
dataType: 'json',
data: $('#sub').serialize(),
success: function (data) {
$("#sub").attr("method", 'GET').attr("action", '/applysuccess');
$('#apply').html('<h3>' + data.message + '</h3>');
$('.count').html(' ' + data.count + ' ');
}
});
<!--这是表单的代码-->
<form action="/apply" method="post" id="sub">
<div class="form-group fl col-md-4">
<input class="form-control" name="first_name" placeholder="first name" required>
<input class="form-control" name="last_name" placeholder="last name" required>
</div>
<div class="form-group fl col-md-4">
<input class="form-control" name="position_id" placeholder="position id" required>
<input class="form-control" name="years_experience" placeholder="years experience" required>
</div>
<div class="form-group fl col-md-4">
<input class="form-control" name="expertise" placeholder="expertise" required>
<button id="applyBtn" type="submit" class="btn btn-primary btn-lg">Apply for Job NOW</button>
</div>
</form>
请输入代码
慕田峪7331174
相关分类