我试图通过Netsuite中的AJAX发布一个表单,以便我可以在表单提交后触发一个事件而不实际重新加载它。
请帮帮我,我是AJAX的新手。
这是代码
$('#du_joinnow').submit(function(e){
e.preventDefault(); //STOP default action
var formdata = $(this).serializeArray();
$.ajaxSubmit({
type: "POST",
url: "https://forms.na1.netsuite.com/app/site/crm/externalleadpage.nl?compid=XXXXXX&formid=1&h=XXXXXXXXXXXXXX"+ formdata,
data: formdata,
success:function(data, textStatus, jqXHR) {
$('#overlay').fadeIn(); //data: return data from server
},
error: function(jqXHR, textStatus, errorThrown) {
alert("Ajax Call Failed.");//if fails
}
});
return false;
});
答案 0 :(得分:0)
而不是$.ajaxSubmit
做$.ajax
完整代码:
$('#du_joinnow').submit(function (e) {
e.preventDefault(); //STOP default action
var formdata = $(this).serializeArray();
$.ajax({
type: "POST",
url: "https://forms.na1.netsuite.com/app/site/crm/externalleadpage.nl?compid=XXXXXX&formid=1&h=XXXXXXXXXXXXXX" + formdata,
data: formdata,
success: function (data, textStatus, jqXHR) {
$('#overlay').fadeIn(); //data: return data from server
},
error: function (jqXHR, textStatus, errorThrown) {
alert("Ajax Call Failed."); //if fails
}
});
return false;
});
答案 1 :(得分:0)
试试这个,
$('#du_joinnow').submit(function(e){
e.preventDefault(); //STOP default action
var formdata = $(this).serializeArray();
$.ajax({
url:"https://forms.na1.netsuite.com/app/site/crm/externalleadpage.nl?compid=XXXXXX&formid=1&h=XXXXXXXXXXXXXX" + formdata,
type:"POST",
data: formdata,
complete:function(data) {
if (data.readyState == 4)
{
if (data.status == 200)
{
$('#overlay').fadeIn();
alert(data.responseText);
}
else
{
alert("Ajax Call Failed.");
alert(data.statusText);
}
}
}
});
return false;
});