我是Ajax的新手,所以我正在尝试修复一些预建的表单。在提交表单时我正在用我的脑子绞尽脑汁,而不是处理它我被发送到“未找到的页面”并且出现错误“无法调用方法'未定义的参数'
我已将html编码如下:
<form id="renewalFormSendTEST">
<fieldset class="sidebarForm">
<ul>
<li>
<label for="name">Name:</label>
<input class="contact-input required" name="name" type="text" />
</li>
<li>
<label for="email">Email:</label>
<input id="email" class="contact-input required email" name="renewalemail" type="text" />
</li>
<li>
<label for="phone">Phone:</label>
<input class="contact-input required" name="phone" type="text" />
</li>
<li>
<label for="product">Product:</label>
<select name="product" class="required">
<option selected="selected"></option>
<option value="Car Insurance">Car Insurance</option>
<option value="Van Insurance">Van Insurance</option>
</select>
</li>
<li>
<label>Renewal Date:</label>
<select name="renewalday" class="contact-input renewalday required">
<option selected="selected"></option>
<option value="1st">01</option>
<option value="2nd">02</option>
<option value="3rd">03</option>
<option value="4th">04</option>
</select>
<select name="renewalmonth" class="contact-input renewalmonth required">
<option selected="selected"></option>
<option value="January">Jan</option>
<option value="February">Feb</option>
</select>
<select name="renewalyear" class="contact-input renewalyear required">
<option selected="selected"></option>
<option>1935</option>
<option>1934</option>
<option>1933</option>
<option>1932</option>
<option>1931</option>
<option>1930</option>
</select>
</li>
<li>
<input class="contact-submit" name="submit" type="submit" value="Send Reminder" />
</li>
</ul>
</fieldset>
</form>
我的处理.js脚本如下所示:
jQuery("#renewalFormSendTEST").validate({
submitHandler: function (form) {
var all = extractFormsData();
jQuery.ajax({
type: "POST",
//url: "/wp-content/themes/equotedirect/library/media/forms/renewal-form-send.php",
url: "<?php bloginfo('template_url'); ?>/wp-content/themes/equotedirect/library/media/forms/test-send.php",
data: jQuery.param(all),
success: function(data)
{
alert("SUCCESS");
}/*,
error: function(xhtp, txt, err)
{
alert("ERROR");
}*/
});
另外,@ScottSelby和@JoeFletch(谢谢你们!)的请求下面是extractFormsData函数的代码:
function extractFormsData() {
var formDataArray = jQuery("form").map(function(idx, ele) {
return jQuery.map(jQuery(ele).serializeArray(), function(ele) {
var obj = {};
obj[ele.name] = ele.value;
return obj;
});
});
var all = {};
jQuery.each(formDataArray, function(index, ele) {
jQuery(ele).each(function(index, ele2) {
jQuery.extend(all,ele2);
});
});
return all;
}
我几个小时以来一直盯着我的屏幕,所以任何帮助都会非常感激。
非常感谢