Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php jquery ajax表单成功消息不工作_Php_Jquery_Ajax_Forms_Contact - Fatal编程技术网

Php jquery ajax表单成功消息不工作

Php jquery ajax表单成功消息不工作,php,jquery,ajax,forms,contact,Php,Jquery,Ajax,Forms,Contact,jquery ajax表单:仅加载图像,不停止,成功消息不起作用 (function() { if($('#contactform').length) { var $form = $('#contactform'), $loader = '<img src="images/preloader.gif" alt="Loading..." />'; $form.append('<div class="hidden" id=

jquery ajax表单:仅加载图像,不停止,成功消息不起作用

(function() {

    if($('#contactform').length) {

        var $form = $('#contactform'),
        $loader = '<img src="images/preloader.gif" alt="Loading..." />';
        $form.append('<div class="hidden" id="contact_form_responce">');

        var $response = $('#contact_form_responce');
        var $p
        $response.append('<p></p>');

        $form.submit(function(e){

            $response.find('p').html($loader);

            var data = {
                action: "contact_form_request",
                values: $("#contactform").serialize()
            };

            //send data to server
            $.post("php/contact-send.php", data, function(response) {

                response = $.parseJSON(response);

                $(".wrong-data").removeClass("wrong-data");
                $response.find('img').remove();

                if(response.is_errors){

                    $response.find('p').removeClass().addClass("error type-2");
                    $.each(response.info,function(input_name, input_label) {

                        $("[name="+input_name+"]").addClass("wrong-data");
                        $response.find('p').append('Please enter correctly "'+input_label+'"!'+ '</br>');
                    });

                } else {

                    $response.find('p').removeClass().addClass('success type-2');

                    if(response.info == 'success'){

                        $response.find('p').append('Your email has been sent!');
                        $form.find('input:not(input[type="submit"], button), textarea, select').val('').attr( 'checked', false );
                        $response.delay(1500).hide(400);
                    }

                    if(response.info == 'server_fail'){
                        $response.find('p').append('Server failed. Send later!');
                    }
                }

                // Scroll to bottom of the form to show respond message
                var bottomPosition = $form.offset().top + $form.outerHeight() - $(window).height();

                if($(document).scrollTop() < bottomPosition) {
                    $('html, body').animate({
                        scrollTop : bottomPosition
                    });
                }

                if(!$('#contact_form_responce').css('display') == 'block') {
                    $response.show(450);
                }

            });

            e.preventDefault();

        });             

    }

})();
这是我的联系方式

            <form method="post" action="" class="comments-form" id="contactform" />

                <p class="input-block">
                    <label for="name">Name:</label>
                    <input type="text" name="name" id="name" />
                </p>

                <p class="input-block">
                    <label for="email">E-mail:</label>
                    <input type="text" name="email" id="email" />
                </p>

                <p class="input-block">
                    <label for="message">Message:</label>
                    <textarea name="message" id="message" cols="30" rows="10"></textarea>   
                </p>

                <p class="input-block">
                    <button class="button default" type="submit" id="submit">Submit</button>
                </p>

            </form>

我认为你的问题在于:

$.post("php/contact-send.php", data, function(response) {

            response = $.parseJSON(response);
       //--^--------------------------------------missing '$' 

            $(".wrong-data").removeClass("wrong-data");
            $response.find('img').remove();
      //----^------------------------------------used the '$' for other codes
尝试在此处放置
$
,看看这是否解决了问题:

$response = $.parseJSON(response);

如果您遇到一些ajax错误,请提出来。

我的jquery代码还有其他选择吗?我仍然想使用加载图像..我们需要查看响应php ui的代码,而不是如何存储它:)我已经在响应上添加了$符号,但仍然得到了相同的错误。php工作得很好,但我的数据库中有空值。加载映像没有停止,我没有收到任何响应消息:(您是否为
$post()
提供了
dataType='json'
$.post
的右括号如下:
},'json')还有其他替代方案吗?
$response = $.parseJSON(response);