donglao4370 2016-09-06 05:41
浏览 38
已采纳

如何知道ajax在jquery中是否完整?

There is a generated form from contact form 7 in wordpress. I would like to know if this is the right way of coding in getting the output messages from contact form after it submit and return the messages (either success or not). This code work but it double send the ajax form.

ajaxArgs = {
   url: 'http://sample.net/',
        success: function () {
            var a= $(".wpcf7-response-output").html();
          console.log(a);
        }
    };
$(".wpcf7-form").bind('submit', function() {
  jQuery.ajax(ajaxArgs);
});

if you submit the form from contact form 7. it works in ajax way and I want to get the error or success message after it complete the ajax. I need your advice guys if this is good enough or please if you have a code that makes it better to use.

  • 写回答

4条回答 默认 最新

  • duanpin9531 2016-09-06 05:47
    关注
    $.ajax({
        type : "POST",
        url : "${pageContext.request.contextPath}/yourUrl",
        data : {
            key1 : "value1" ,
            key2 : "value2"
        },
        async : true, // if you want wait until ajax done, you should set "async" false
        complete : function(){
            console.log("[JQUERY AJAX COMPLETE]");
        }
        success : function(){
            console.log("success");
        }, 
        error : function () {
            console.log("fail");
        }
    });
    

    You can know ajax complete at "complete"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题