我知道在SO中已经多次询问过,但使用这些答案并没有解决我的问题。
下面的脚本:
$(document).on('submit','.stack_survey_form',function(e)
{
e.preventDefault();
var form = $(this);
setPhoneAndAddress(form);
if(form.attr('action') != '') {
$.ajax({
url: form.attr('action'),
dataType: 'jsonp',
contentType: "application/javascript; charset=utf-8",
data: form.serialize(),
error: function (jqXHR, text, errorThrown) {
console.log(jqXHR + " " + text + " " + errorThrown);
form.attr('data-sent','true').data('sent','true');
},
success: function(data) {
console.log(data);
console.log('SUCCESS');
form.attr('data-sent','true').data('sent','true');
submitForm();
}
});
console.log('SENT');
}else {
console.log('SKIP');
}
});
HTML表单:
<form method="get" name="hostedform" class="stack_survey_form" enctype="text" action="http://myurl.com/sendData/">
//some content here
</form>
更新
响应:
{"status":"lead_received","message":"Lead received for processing","lead_id":4177110}