weixin_33682790 2017-09-15 10:26 采纳率: 0%
浏览 26

没有调用AJAX

I'm having an issue with AJAX as for some reason it either isn't being called or isn't working

$(document).ready(function() {
  $("#my_form").submit(function(event) {
    alert("submited");

    event.preventDefault("#my_form");

    var post_url = $(this).attr("action"); //get form action url
    var request_method = $(this).attr("method"); //get form GET/POST method
    var form_data = $(this).serialize(); //Encode form elements for submission

    alert(post_url + "" + request_method + " " + form_data);

    $.ajax({
      type: post_url,
      url: request_method,
      data: form_data,
      success: function(data) {
        alert(data);
        $("server-results").html(data);
      }
    });

    $('#loadingDiv').hide().ajaxStart(function() {
      $(this).show();
    });
    //.ajaxStop(function() {
    //  $(this).hide();
    //});
  });
});

I've debugged as much as I could and there is no issue with the form function being activated in JavaScript or the 3 variables being transported into the JS code block. However ajaxStart doesn't activate which makes me believe that the problem is with just ajax.

I also checked the link to ajax and it seems to be working however I'm not sure if its the right link or if it's not valid for whatever reason.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

FYI the ajax link is at the top of the page above both HTML and JS.

  • 写回答

2条回答 默认 最新

  • ℙℕℤℝ 2017-09-15 10:32
    关注

    You have passed wrong parameters:

    type: post_url,
    url: request_method,
    

    You need to pass post_url in url and request_method in type. Just change it to:

    type: request_method,
    url: post_url,
    
    评论

报告相同问题?

悬赏问题

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