Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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_Validation - Fatal编程技术网

Php 表单提交后未显示确认消息-jQuery/Ajax

Php 表单提交后未显示确认消息-jQuery/Ajax,php,jquery,ajax,forms,validation,Php,Jquery,Ajax,Forms,Validation,我在这里学习教程:以及正确发送数据的表单。但是,单击提交后,表单只显示“正在发送”消息,而不显示确认消息。当我在本地和开发环境上进行测试时,就会发生这种情况。我在控制台中没有看到任何错误消息 这是我第一次使用ajax,我是jQuery/JavaScript的新手。我不确定这里有什么问题。看来它并没有把数据解读为真实的。我将“真”改为“假”,看看会发生什么,但仍然不起作用。有人能帮忙吗 仅供参考,我在一个已经调用1.3.2 jQuery库的站点上实现了这一点,并且无法删除引用,因此我必须使用noC

我在这里学习教程:以及正确发送数据的表单。但是,单击提交后,表单只显示“正在发送”消息,而不显示确认消息。当我在本地和开发环境上进行测试时,就会发生这种情况。我在控制台中没有看到任何错误消息

这是我第一次使用ajax,我是jQuery/JavaScript的新手。我不确定这里有什么问题。看来它并没有把数据解读为真实的。我将“真”改为“假”,看看会发生什么,但仍然不起作用。有人能帮忙吗

仅供参考,我在一个已经调用1.3.2 jQuery库的站点上实现了这一点,并且无法删除引用,因此我必须使用noConflict。当我只引用较旧的库时,这不起作用

我的目标是创建一个在用户进入网站时弹出的模式,但不是在设置了cookie或者在他们进入的页面上已经有特定的div时

以下是脚本:

          <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
          <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
          <script type="text/javascript" src="/wcsstore/CVWEB/images/home/js/jquery.fancybox.js?v=2.0.6"></script> 

    <script type="text/javascript">
    var jQuery_1_7_2 = jQuery.noConflict(true);
    function validateEmail(email) { 
        var reg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return reg.test(email);
    }
    jQuery_1_7_2(document).ready(function(){
            var emailFormExists = jQuery_1_7_2('#e2ma_signup_form');
            if (document.cookie.indexOf('visited=true') == -1 && !(emailFormExists.length)){
                var fifteenDays = 1000*60*60*24*15;
                var expires = new Date((new Date()).valueOf() + fifteenDays);
                document.cookie = "visited=true;expires=" + expires.toUTCString();
                jQuery_1_7_2.fancybox({width:"100%", inline:true, href:"#inline"});
            }
            else
            {
            jQuery_1_7_2('#e2ma_signup_form').length
                var fifteenDays = 1000*60*60*24*15;
                var expires = new Date((new Date()).valueOf() + fifteenDays);
                document.cookie = "visited=true;expires=" + expires.toUTCString();  
            }
        jQuery_1_7_2("#contact").submit(function() { return false; });


    jQuery_1_7_2("#send").on("click", function(){
        var emailval  = jQuery_1_7_2("#email").val();
        var mailvalid = validateEmail(emailval);

        if(mailvalid == false) {
            jQuery_1_7_2("#email").addClass("error");
        }
        else if(mailvalid == true){
            jQuery_1_7_2("#email").removeClass("error");
        }

        if(mailvalid == true) {
            // if both validate we attempt to send the e-mail
            // first we hide the submit btn so the user doesnt click twice
            jQuery_1_7_2("#send").replaceWith("<em>sending...</em>");

            jQuery_1_7_2.ajax({
                type: 'POST',
                url: 'http://lcoawebservices.com/scripts/email-opt-in.php',
                data: jQuery_1_7_2("#contact").serialize(),
                success: function(data) {
                    if(data == "true") {
                        jQuery_1_7_2("#contact").fadeOut("fast", function(){
                            jQuery_1_7_2(this).before("<p><strong>Thanks for opting in!</strong></p>");
                            setTimeout("jQuery_1_7_2.fancybox.close()", 1000);
                        });
                    }
                }
            });
        }
    }); 
                });
            </script>

var jQuery_1_7_2=jQuery.noConflict(true);
功能验证邮件(电子邮件){
变量reg=/^([^()[\]\\,;:\s@\“]+(\.[^()[\]\,;:\s@\“]+*)(\'+\”)(\[[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[1,3}.];
返回注册测试(电子邮件);
}
jQuery_1_7_2(文档).ready(函数(){
var emailFormExists=jQuery_1_7_2('e2ma_signup_form');
if(document.cookie.indexOf('visted=true')=-1&&!(emailFormExists.length)){
变量五天=1000*60*60*24*15;
var expires=新日期((新日期()).valueOf()+五个星期);
document.cookie=“visited=true;expires=“+expires.toutString();
jQuery_1_7_2.fancybox({width:“100%”,inline:true,href:“#inline”});
}
其他的
{
jQuery_1_7_2('#e2ma_signup_form')。长度
变量五天=1000*60*60*24*15;
var expires=新日期((新日期()).valueOf()+五个星期);
document.cookie=“visited=true;expires=“+expires.toutString();
}
jQuery_1_7_2(“#contact”).submit(函数(){return false;});
jQuery_1_7_2(“#发送”)。在(“单击”,函数()上{
var emailval=jQuery_1_7_2(“电子邮件”).val();
var mailvalid=validateEmail(emailval);
if(mailvalid==false){
jQuery_1_7_2(“电子邮件”).addClass(“错误”);
}
else if(mailvalid==true){
jQuery_1_7_2(“电子邮件”).removeClass(“错误”);
}
if(mailvalid==true){
//如果两者都有效,我们将尝试发送电子邮件
//首先,我们隐藏提交btn,这样用户就不会点击两次
jQuery_1_7_2(“#发送”).replace为(“发送…”);
jQuery_1_7_2.ajax({
键入:“POST”,
网址:'http://lcoawebservices.com/scripts/email-opt-in.php',
数据:jQuery_1_7_2(“#联系人”).serialize(),
成功:功能(数据){
如果(数据==“真”){
jQuery_1_7_2(“#联系人”).fadeOut(“快速”,函数(){
jQuery_1_7_2(此)。在(“感谢您选择加入!”)之前;
setTimeout(“jQuery_1_7_2.fancybox.close()”,1000);
});
}
}
});
}
}); 
});
以下是HTML:

            <div id="inline">
                <h2>Join the our mailing list!</h2>

                <form id="contact" name="contact" action="#" method="post">
                    <label for="email">Your E-mail</label>
                    <input type="email" id="email" name="email" class="txt">
                    <button id="send">Send E-mail</button>
                </form>
            </div>  

加入我们的邮件列表!
你的电子邮件
发送电子邮件
这里是php(我也是新手)


我想出来了-这是由于跨域访问问题造成的。我还没有关于如何解决这个问题的答案,但我想发布这篇文章,这样就没有人花时间查看我的代码,试图修复它。

我遇到了这个问题,我发现我的PHP中有一个语法错误。你有错误日志可以查阅吗?或者你可以发布你的脚本吗?@Sneagan也添加了PHP。你知道你不需要到处写
jQuery\u 1\u 7\u 2
。只需将其全部封装在参数为
$
的函数中,并使用
jQuery\u 1\u 7\u 2
@mkoryak调用它,不,我不知道。这就是我被教导不冲突的方式。我对这一点很陌生,不知道如何写出你的建议。有没有控制台错误?还可以在ajax中实现
错误
处理程序,就像为
成功
所做的那样@mkoryak提交一个例子,你的解释不够清楚,如果是跨领域的,那将是一个困难的例子:(
        <?php
        $sendto   = "llantz@lecreuset.com";
        $usermail = $_POST['email'];
        $content  = nl2br($_POST['msg']);

        $subject  = "New Feedback Message";
        $headers  = "From: " . strip_tags($usermail) . "\r\n";
        $headers .= "Reply-To: ". strip_tags($usermail) . "\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html;charset=utf-8 \r\n";

        $msg  = "<html><body style='font-family:Arial,sans-serif;'>";
        $msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>New User Feedback</h2>\r\n";
        $msg .= "<p><strong>Sent by:</strong> ".$usermail."</p>\r\n";
        $msg .= "<p><strong>Message:</strong> ".$content."</p>\r\n";
        $msg .= "</body></html>";


        if(@mail($sendto, $subject, $msg, $headers)) {
            echo "true";
        } else {
            echo "false";
        }

        ?>