Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.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
Javascript Ajax成功响应不起作用。不在IE11上传递数据_Javascript_Php_Json_Ajax - Fatal编程技术网

Javascript Ajax成功响应不起作用。不在IE11上传递数据

Javascript Ajax成功响应不起作用。不在IE11上传递数据,javascript,php,json,ajax,Javascript,Php,Json,Ajax,很抱歉,这个标题叫戈尔,我有点不知所措,我已经尝试了所有我能在网上找到的东西。我试图通过post将数据传递到我的sendjs.php文件,但我遇到了一个问题 ajaxsuccess函数不应用if语句 现场站点:www.diysoakwells.com.au(您可以添加项目并结帐以进行测试) 我甚至不知道从哪里开始诚实,所以任何信息都会很感激,我会根据要求用任何信息更新帖子 app.js $(function() { // Get the form. var form = $(

很抱歉,这个标题叫戈尔,我有点不知所措,我已经尝试了所有我能在网上找到的东西。我试图通过post将数据传递到我的sendjs.php文件,但我遇到了一个问题

  • ajax
    success
    函数不应用if语句
  • 现场站点:www.diysoakwells.com.au(您可以添加项目并结帐以进行测试)

    我甚至不知道从哪里开始诚实,所以任何信息都会很感激,我会根据要求用任何信息更新帖子

    app.js

    $(function() {
    
    
        // Get the form.
        var form = $("#ajax-contact");
    
        // Get the messages div.
        var formMessages = $("#form-messages");
    
        var spinner = $("#spinner");
    
        var submit = $("#submit");
    
        // Set up an event listener for the contact form.
        $(form).submit(function(e) {
            // Stop the browser from submitting the form.
            e.preventDefault();
    
            //display the cog animation
            $(spinner).removeClass("hidden");
            //hide the submit button
            $(submit).addClass("hidden");
    
    
    
            jsonObj=[];
            for(i=1;i<$(".item-price").length;i++)
            {
                var items={};
                var itemname = $(".item-name").get(i);
                var itemprice = $(".item-price").get(i);
                var itemquantity = $(".item-quantity").get(i);
                var itemtotal = $(".item-total").get(i);
                items["name"] = itemname.innerHTML;
                items["price"] = itemprice.innerHTML;
                items["quantity"] = itemquantity.innerHTML;
                items["total"] = itemtotal.innerHTML;
                jsonObj.push(items);
    
            }
    
            console.log(items);
    
            var formdata = {};
            formdata["textbox"] = $("#textbox").val();
            formdata["name"] = $("#name").val();
            formdata["phone"] = $("#phone").val();
            formdata["email"] = $("#email").val();
            formdata["address"] = $("#address").val();
            formdata["grandtotal"] = simpleCart.grandTotal();
            var x = 
            {
                "cart" : jsonObj,
                "formdata" : formdata,
                "captchaResponse" : $("#g-recaptcha-response").val()
            };
            //jsonString = jsonObj+formdata;
            var y = JSON.stringify(x);
            console.log(y);
            var result = jQuery.parseJSON(y);
            console.log(result);
    
    
            // Serialize the form data.
            //var formData = $(form).serialize();
    
            // Submit the form using AJAX.
            $.ajax({
                type: "post",
                url: "sendjs.php" ,
                //url: $(form).attr("action"),
                data: y,
                contentType: "application/json; charset=utf-8",
                traditional: true,
                success: function (response) {
                            if(response=="Thank You! Your message has been sent.")
                            {
                        //remove the button animation
                        $(spinner).addClass("hidden");
                        $(formMessages).removeClass("error");
                        $(formMessages).addClass("success");
                        $("#textbox").val("");
                        $("#name").val("");
                        $("#email").val("");
                        $("#message").val("");
                        $("#phone").val("");
                        $("#address").val("");
    
                            }
                            else
                            {
                        $(formMessages).removeClass("success");
                        $(formMessages).addClass("error");
                        $(spinner).addClass("hidden");
                        $(submit).removeClass("hidden");
                            }
    
                    $(formMessages).text(response);
    
                }
            });
        });
    
    });
    
    $(函数(){
    //去拿表格。
    var form=$(“#ajax联系人”);
    //获取消息div。
    var formMessages=$(“#表单消息”);
    变量微调器=$(“#微调器”);
    var提交=$(“#提交”);
    //为联系人窗体设置事件侦听器。
    $(表格)。提交(功能(e){
    //停止浏览器提交表单。
    e、 预防默认值();
    //显示cog动画
    $(微调器).removeClass(“隐藏”);
    //隐藏提交按钮
    $(提交).addClass(“隐藏”);
    jsonObj=[];
    对于(i=1;i
    

    希望有人能给我一些建议。

    因为您的情况是
    回复==“谢谢!您的邮件已经发送了。”

    你的结果是
    “请点击验证码”,“谢谢。您的订单已发送,副本已发送到您的收件箱”,“我们的服务器出现问题,请拨打0420 903 950或发送电子邮件contact@diysoakwells.com.au.“


    因此,您的所有结果都将用于其他部分

    您如何确定“
    jsonObj
    未在IE11上传递?”?您应该能够看到网络控制台中发布的数据。因此,您不需要
    传统的
    属性;这仅适用于
    应用程序/x-www-form-urlencoded
    数据。事实上,您可能应该将
    processData:false设置为false。谢谢phil。我将把问题分成两部分,并根据需要进行更新特德。
    
    <?php
    //Debugging
    //ini_set( 'display_errors', 1 );
    //error_reporting( E_ALL );
    
    //replaces file_get_contents due to restrictions on server
    function get_data($url)
        {
          $ch = curl_init();
          $timeout = 5;
          curl_setopt($ch,CURLOPT_URL,$url);
          curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
          $data = curl_exec($ch);
          curl_close($ch);
          return $data;
        }
    
        //turn url_fopen on due to restrictions on server
        //ini_set('allow_url_fopen', true);
    
        date_default_timezone_set('Australia/Perth');
        $time = date ("h:i A"); 
        $date = date ("l, F jS, Y");
        $json = file_get_contents('php://input');
        $obj = json_decode($json,true);
        $captcha = $obj["captchaResponse"];
        $captcha;
        $secretKey = "scrubbed";
        $ip = $_SERVER['REMOTE_ADDR'];
        $response = get_data("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
    
        //not used due to server restictions
        //$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
    
        $responseKeys = json_decode($response,true);
    
        if(intval($responseKeys["success"]) !== 1) {
            echo "Please Click on the Captcha";
            return false;
        }
        else 
        {
        //echo $items;
        $name = $obj["formdata"]["name"];
        $phone = $obj["formdata"]["phone"];
        $email = $obj["formdata"]["email"];
        $textbox = $obj["formdata"]["textbox"];
        $address = $obj["formdata"]["address"];
        $grandtotal  = $obj["formdata"]["grandtotal"];
        $text = "<html style='font-family:arial'>
        <body>
            <h1 style='color:crimson;'>DIY Soakwells</h1>
            <p>This order was submitted from www.diysoakwells.com.au on $date at $time</p>
            <p>$name thank you for your order inquiry. Deliveries are normally every Friday, we will be in contact shortly to discuss your order and confirm a time.</p>
            <p>An invoice will be issued after delivery for payment via bank transfer.</p>
            <p>In the meantime if you haven't already seen it, you can take a look at www.soakwellcalculator.com.au to confirm the number of soakwells you ordered will be adequate.</p>
            <br>
    
            <h2 style='color:crimson;'>CUSTOMER DETAILS</h2>
            <p><b>Email:</b>\n$email</p>
            <p><b>Name:</b>\n$name</p>
            <p><b>Phone:</b>\n$phone</p>
            <p><b>Delivery Address:</b>\n$address</p>
            <p><b>Message:</b>\n$textbox</p>
            <br>
    
            <h2 style='color:crimson;'>ORDER DETAILS</h2>";
    
            $items_in_cart = count($obj["cart"]);
            for($i=0; $i < $items_in_cart; $i++) {
                $iname = $obj["cart"][$i]["name"];
                $price = $obj["cart"][$i]["price"]; 
                $quantity = $obj["cart"][$i]["quantity"];
                $total = $obj["cart"][$i]["total"];
                //display looped cart data      
                $items .= "<p>$iname x $quantity - $price <small>ea.</small> <b>Sub Total: </b> $total .</p>";
            }
    
            $final_total ="<br>
            <p><b>Total: </b>$$grandtotal <small>inc. GST</small></p>
            </body>
            </html>";
    
            //Email Content
            $body = $text.$items.$final_total;
    
            // Set the email subject.
            $subject = "New order from $name";
    
            // Build the email content.
            $email_content = $body;
    
            // Build the email headers.
            $email_headers = 'MIME-Version: 1.0' . PHP_EOL;
            $email_headers .= 'Content-Type: text/html; charset=ISO-8859-1' . PHP_EOL;
            //$email_headers .= 'To:' . $name . '<' . $email . '>' . PHP_EOL;
            $email_headers .= 'From: DIY Soakwells <orders@diysoakwells.com>' . PHP_EOL;
            $email_headers .= 'CC: orders@diysoakwells.com.au' . PHP_EOL;
            $email_headers .= 'Reply-To: DIY Soakwells <orders@diysoakwells.com.au>' . PHP_EOL;
            $email_headers .= 'Return-Path: DIY Soakwells <orders@diysoakwells.com>' . PHP_EOL;
            $email_headers .= 'X-Sender: DIY Soakwells <orders@diysoakwells.com.au' . PHP_EOL;
            $email_headers .= 'X-Mailer: PHP/' . phpversion() . PHP_EOL;
            //$email_headers .= 'X-Priority: 1' . PHP_EOL;
    
    
    
            //validate Email
            $email_check = filter_input(INPUT_POST, $email, FILTER_VALIDATE_EMAIL);
            //Recipients
            $to = $email;
    
            if (mail($to, $subject, $email_content, $email_headers, '-forders@diysoakwells.com.au')) {
                // Set a 200 (okay) response code.
                //http_response_code(200);
                echo "Thank You. Your order has been sent and a copy mailed to your inbox.";
            } else {
                // Set a 500 (internal server error) response code.
                //http_response_code(500);
                echo "There appears to be an issue with our server, please ring 0420 903 950 or email contact@diysoakwells.com.au.";
            }      
        }       
    ?>