这是我的jquery脚本,ajax总是失败,我真的不明白为什么。 这是电话:
<script>
function myFunction()
{
var time = document.getElementById('yearsemployed').value + "years";
var baseurlstring = "http://www.quickinsure.co.za/LeadService/Service.asmx/SubmitLatestLoanLead?";
var paramfirstname = document.getElementById('firstname').value;
var paramlastname = document.getElementById('lastname').value;
var paramemailaddress = document.getElementById('emailaddress').value;
var paramcellnumber = document.getElementById('cellnumber').value;
var paramidnumber = document.getElementById('idnumber').value;
var paramnetsalary = document.getElementById('netsalary').value;
var paramgrosssalary = document.getElementById('grosssalary').value;
var paramloanammount = document.getElementById('loanammount').value;
var paramdebtreview = "FALSE";
if(document.getElementById('debtreview').checked == true)
{
paramdebtreview = "TRUE";
}
var e = document.getElementById("bank");
var parambank = e.options[e.selectedIndex].value;
var params = {
UserId:100405,
Firstname:paramfirstname,
Surname:paramlastname,
Email:paramemailaddress,
CellNo:paramcellnumber,
WorkNo:paramcellnumber,
IdNo:paramidnumber,
NetSalary:paramnetsalary,
GrossSalary:paramgrosssalary,
LoanAmount:paramloanammount,
EmploymentTime:time,
UnderDebtReview:paramdebtreview,
Bank:parambank,
SubId:"affcoza_1829_397",
TestMode:"TRUE"
};
str = jQuery.param( params );
var callbackurl = baseurlstring + str;
getloanapplicationcallback(callbackurl);
}
function successCallBack(returnData){
window.location = 'http://www.lowcreditloans.co.za/thank-you-for-submitting/';
}
function errorCallBack(){
window.location = 'http://www.lowcreditloans.co.za/error-processing-request/';
}
function getloanapplicationcallback(callbackurl)
{
// this will generate another thread to run in another function
jQuery.ajax({
url: callbackurl,
type: 'get',
success: successCallBack,
error: errorCallBack
});
}
</script>
这是php:
<form id="new_post" name="new_post" method="post" action="" enctype="multipart/form-data">
<div id="et_contact_left">
<h3 style="padding-bottom:10px">Personal Details:</h3>
<p class="clearfix">
<label for="title">First Name:</label>
<input type="text" required="true" id="firstname" value="" tabindex="1" name="firstname" class="input"/>
</p>
<p class="clearfix">
<label for="title">Last Name:</label>
<input type="text" required="true" id="lastname" value="" tabindex="2" name="lastname" class="input"/>
</p>
<p class="clearfix">
<label for="title">Email:</label>
<input type="text" required="true" id="emailaddress" value="" tabindex="3" name="emailaddress" class="input"/>
</p>
<p class="clearfix">
<label for="title">Cell Number:</label>
<input type="text" required="true" id="cellnumber" value="" tabindex="4" name="cellnumber" class="input"/>
</p>
<p class="clearfix">
<label for="title">Id Number:</label>
<input type="text" required="true" id="idnumber" value="" tabindex="5" name="idnumber" class="input"/>
</p>
<p class="clearfix">
<label for="title">Years Employed:</label>
<input type="text" required="true" id="yearsemployed" value="0" tabindex="6" name="yearsemployed" class="input"/>
<label for="title">Months Employed:</label>
<input type="text" required="true" id="monthsemployed" value="0" tabindex="7" name="monthsemployed" class="input"/>
</p>
<h3>Employment Details:</h3>
<p class="clearfix">
<label for="title">Monthly Gross Salary:</label>
<input type="text" required="true" id="grosssalary" value="" tabindex="8" name="grosssalary" class="input"/>
</p>
<p class="clearfix">
<label for="title">Monthly Net Salary:</label>
<input type="text" required="true" id="netsalary" value="" tabindex="9" name="netsalary" class="input"/>
</p>
<p class="clearfix">
<label for="title">Loan Ammount:</label>
<input type="text" required="true" id="loanammount" value="" tabindex="10" name="loanammount" class="input"/>
</p>
<p class="clearfix">
<label for="title">Total Monthly Expneses:</label>
<input type="text" required="true" id="grosssalary" value="" tabindex="11" name="grosssalary" class="input"/>
</p>
<p class="clearfix">
<label for="title">Bank:</label>
<select name="bank" id="bank" tabindex="6">
<option value="0">First National Bank</option>
<option value="1">ABSA Bank</option>
<option value="2">Nedbank</option>
<option value="3">Standerd Bank</option>
<option value="4">Capitec Bank</option>
<option value="5">Bidvest Bank</option>
<option value="6">RMB</option>
<option value="7">Investec Bank</option>
<option value="8" selected="selected">Other</option>
</select>
</p>
<p class="clearfix">
<label for="title">Paydate:</label>
<input type="text" required="true" id="grosssalary" value="25" tabindex="12" name="grosssalary" class="input"/>
</p>
<p class="clearfix">
<label for="title">Are you under debt review?</label>
<input type="checkbox" id="debtreview" name="debtreview" value="" />
</p>
<p class="clearfix">
<label for="title">Preform Credit Check with Id-Number?</label>
<input type="checkbox" id="creditcheck" name="creditcheck" checked="checked" />
</p>
<p class="clearfix">
<label for="title">I Accept the Terms and Conditions</label>
<input type="checkbox" id="termsandconditions" name="termsandconditions" checked="checked" />
</p>
</div> <!-- et_contact_left -->
<input type="submit" value="Submit Application" tabindex="40" id="submit" name="submit" class="et_contact_submit" onclick=" myFunction()" />
</form>
答案 0 :(得分:0)
为避免浏览器默认提交行为,请添加
return false;
在您的onclick或功能结束时。否则表格将被提交=&gt; action =&#34;&#34;表示将表单数据发布到当前URL。
答案 1 :(得分:0)
试试这样:
$.ajax({
type:"GET",
url:callbackurl,
success:function(){
successCallBack();
},
error:function(){
errorCallBack();
}
});
其次,您必须使用return false
,preventDefault
或type=button
代替type=submit
,它将提交给您的form action
,这是空的
答案 2 :(得分:0)
使用type =“button”,preventDefault来改变表单的默认行为。在上面的脚本中,您无需改变Form的行为。