我共享一个提交按钮的jQuery与.getJSON
("#sbtBtn").click(function() {
if($("input[name=license_code]").val()) { //check if #retUser has a value
$("#formOne").submit();
} else if ($("input[name=referred_by_text]").val() || $("input[name=broker_text]").val() || $("input[name=email1]").val()) {
$("#formTwo").submit();
}
});
为“#formOne”我试图使用jQuery的功能的getJSON使用脚本跨域,它不工作2种形式。
$("#formOne").validate({
errorElement: "em",
errorPlacement: function(error, element) {
error.appendTo(element.parent("li"));
},
submitHandler: function(form) {
var dataString = $(form).serialize();
$.getJSON("http://www.domain.com/sugar/NT7Lead2.php?data=" + escape($(this).serialize()) + "&callback=?", function(data) {
$("#results").html(data);
});
return false;
},
rules: {
license_code: {
minlength: 3,
maxlength: 39
}
},
messages: {
license_code: {
minlength: "Your License be at Least 3 Characters Including Dashes",
maxlength: "Your License Key Cannot Be More Than 39 Characters Including Dashes"
}
}
});
当我在Firebug查看,该数据是从脚本返回,但它不是被添加到“#results”。这里有什么明显的错误吗?我还需要将脚本包含在JSON函数中的表单操作中吗?这里是html
<div class="purchaseFormContain" id="currentUser">
<div class="purchaseTH form" id="formOneTH"><h3>Current Users</h3></div>
<form method="post" name="formOne" id="formOne">
<ul class="features">
<li><label for="license_code">Enter Your License Key Here</label></li>
<li><input type="text" name="license_code" /></li>
</ul>
</form>
<div class="clear"></div>
<div id="results"></div>
<!--/retUser purchaseFormContain --></div>
请帮助! THX
我不这么认为。当我输入表单处理器脚本url + callback = foobar时,如果验证失败,它会在页面上的脚本中显示消息错误消息,而不是回调 – 2010-10-21 13:11:52