首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >不确定调用多个函数的正确方式。我只需要简单的语法帮助

不确定调用多个函数的正确方式。我只需要简单的语法帮助
EN

Stack Overflow用户
提问于 2011-07-27 12:13:02
回答 2查看 89关注 0票数 1

jQuery新手。需要简单语法方面的帮助。

代码语言:javascript
运行
复制
<script>
$(document).ready(function () {
    jQuery.validator.addMethod("phoneUS", function (phone_number, element) {
        phone_number = phone_number.replace(/\s+/g, "");
        return this.optional(element) || phone_number.length > 9 && phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
    }, "Please specify a valid phone number");
    $("#networx_affiliate").validate({
        rules: {
            service_name: "required"
        }
    }).ajaxForm({
        url: '**********',
        target: '#output',
        type: 'post',
        dataType: 'xml',
        success: function processXml(responseXML) {
            // 'responseXML' is the XML document returned by the server; we use 
            // jQuery to extract the content of the message node from the XML doc 
            $(xml).find("affiliateresponse").each(function () {
                $("#output").append($(this).find("successCode") + "<br />");
                $("#output").append($(this).find("errormessage") + "<br />");
            });
        }
    });
});
</script>

我有一个验证表单插件和一个ajax表单插件。请告诉我正确的叫法是什么。因为我现在用的方法ajax似乎不起作用。

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-07-27 14:34:17

如果您想在表单验证后调用ajax方法,可以这样做

代码语言:javascript
运行
复制
$("#networx_affiliate").validate({
        submitHandler: function (form) {
            CallAjaxMethod();
        },

        rules: {
            service_name: "required"
        }
});

function CallAjaxMethod()
{
    $.ajax({
        url: 'https://api.networx.com',
        target: '#output',
        type: 'post',
        dataType: 'xml',
        success: function processXml(responseXML) {
            // 'responseXML' is the XML document returned by the server; we use 
            // jQuery to extract the content of the message node from the XML doc 
            $(xml).find("affiliateresponse").each(function () {
                $("#output").append($(this).find("successCode") + "<br />");
                $("#output").append($(this).find("errormessage") + "<br />");
            });
        }
    });

}
票数 0
EN

Stack Overflow用户

发布于 2011-07-27 14:23:42

.validate()返回验证器而不是表单对象。尝试先调用.ajaxForm(),然后再调用.validate()。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6839350

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档