0

タイトルにあるように、投稿の送信を遅らせるのに苦労しているため、ajax 呼び出しを完了できます。

これまでのところ、これがうまくいかない理由はありますか?

//Jquery
jQuery(document).ready(function($) {
    $("#save").on("click", function(e){


                //Prevent submission of post data before ajax success in function reverse_geocoding
                e.preventDefault();
                //ajax
                reverse_geocoding(lat_onclick,lng_onclick,true);

        }
    });





                    function reverse_geocoding(latitude,longitude,submit) {
                            //get country/city/state using lat and long data
                            jQuery.ajax({
                                url: "<?php bloginfo('template_url'); ?>/reverse-geocoding.php",
                                type: "GET",
                                data: "latitude=" + latitude + "&longitude=" + longitude,
                                cache: false,
                                success: function (data){
                                    var response = jQuery.parseJSON(data);
                                },
                                complete: function() {
                                    if (submit) {
                                        $("#add_to_map").submit();
                                    }
                                }
                            });
                    }
});
//End Jquery

html 部分:

<form method="post" name="update_profile_maps" id="add_to_map" action="">
    //some inputs here.
</form>
4

1 に答える 1

1

<submit>タグを使用する代わりに、法線を使用します<button>(これは type ではありません。 typeがデフォルトでsubmitあることに注意してください)。ボタンがクリックされたら ajax を起動し、ajax が正常に完了した場合は JavaScript を使用してフォームを送信します。submit

于 2013-07-07T16:22:20.750 に答える