duanlu8613 2014-02-26 06:49
浏览 123

jQuery $ .post没有执行,如何修复

I am working on a Plugin for WordPress and am having issues with the js code below executing the $.post.

The js is called, form validation takes place, the form inputs are serialized into post data correctly, the $.post just doesn't execute.

The form is being posted from the Admin, currently I can't get the .submit action to work so am using .click to execute the js function. This may be related to the issue, I am not sure... The form will load without submitting if I use the .submit action, versus using the .click action... never had this issue before and it is pretty frustrating to say the least.

Here is the code:

  jQuery(document).ready(function($) {

    $("#edit_member_submit").click( function() {

        // define

        var numbers = /^[0-9]+$/;

        var referrer_id = $("#referrer_id").val();

        // Validate fields START

        if( !referrer_id.match(numbers) ) {

            alert("Please enter a numeric value");

            return false;           

        }

        // Validate fields END       

        $("#ajax-loading-edit-member").css("visibility", "visible");

        // Convert to name value pairs          
        // Define a data object to send to our PHP      

            $.fn.serializeObject = function() {

                var arrayData, objectData;
                arrayData = this.serializeArray();
                objectData = {};

                $.each(arrayData, function() {
                    var value;

                if (this.value != null) {

                  value = this.value;

                } else {

                  value = '';

                }

                if (objectData[this.name] != null) {

                    if (!objectData[this.name].push) {

                    objectData[this.name] = [objectData[this.name]];

                    }

                    objectData[this.name].push(value);

                    } else {

                    objectData[this.name] = value;

                    }

                });

              return objectData;                    

            };          

        var data = $("#edit_member_form").serializeObject(); //the dynamic form elements.

        //alert(JSON.stringify(data));        

        data.action = "edit_member_info"; //the action to call
        data._ajax_nonce = custajaxobj.nonce; // This is the name of the nonce setup in the localize_script

        // Define the URL for the AJAX to call
        var url = custajaxobj.ajaxurl; 

        //alert( JSON.stringify( data ) );
        //alert( JSON.stringify( url ) );

        $.post(url, data, function(response) {

            $("#ajax-loading-edit-member").css("visibility", "hidden");

            alert(response);

        });

        return false;

    });

});

Seems like the last section is having issues:

$.post(url, data, function(response) {

        $("#ajax-loading-edit-member").css("visibility", "hidden");

        alert(response);

    });
  • 写回答

1条回答 默认 最新

  • douwen3083 2014-02-26 08:01
    关注
    $.post( "ajax/test.html", function( data ) {
    

    $("#ajax-loading-edit-member").css("visibility", "hidden");

        alert(data);
    

    });

    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)