Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.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提交post请求_Javascript_Php_Ajax - Fatal编程技术网

Javascript 无法使用ajax提交post请求

Javascript 无法使用ajax提交post请求,javascript,php,ajax,Javascript,Php,Ajax,home.php中的表单部分 <div id='googleForm'> <form> <div class='item'> <label class='label'>お名前</label> <input class='inputs' type='text' name='entry.1403582438' requ

home.php中的表单部分

<div id='googleForm'>
            <form>

              <div class='item'>
                <label class='label'>お名前</label>
                <input class='inputs' type='text' name='entry.1403582438' required>
              </div>

              <div class='item'>
                <label class='label'>メールアドレス</label>
                <input class='inputs' type='email' name='entry.920640653' required>
              </div>
              <div class='item'>
                <label class='label'>お電話番号</label>
                <input class='inputs' type='text' name='entry.1631209175' required>
             </div>

              <div class='item'>
                <p class='label'>お問合わせの種類</p>
                <div class='inputs'>
                <input id='cut' type='radio' name='entry.1757207008' value='1'><label for="cut">無料体験</label>
                <input id='cut-color' type='radio' name='entry.1757207008'  value='2'><label for="cut-color">料金</label>
                <input id='headspa' type='radio' name='entry.1757207008'  value='3'><label for="headspa">入会について</label>
                <input id='other' type='radio' name='entry.1757207008'  value='4'><label for="other">その他</label>

                </div>
              </div>

              <div class='item'>
                <label class='label'>お問合わせ内容</label>
                <textarea class='inputs' name='entry.669414687' required></textarea>
              </div>

              <div class='btn-area'>
                <input type='submit' value='送信'><input type='reset' value='リセット'>
              </div>

            </form>
        </div>
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
    <script>
      $(function() {
        $('#googleForm').submit(function(e){

                let hostUrl = "https://docs.google.com/forms/u/0/d/e/1FAIpQLSfuXJf8bjE4cYO5f_5g4w-CW0R_LXruvaNG1-veDiEwFh0fEg/formReisponse";
                let name = $('input:text[name="entry.1403582438"]').val();
                let email = $('input[name="entry.920640653"]').val();
                let contact = $('input:text[name="entry.1631209175"]').val();
                let category_id = $('input:radio[name="entry.1757207008"]:checked').val();
                let inquiry = $('textarea[name="entry.669414687"]').val();
                $.ajax({
                   url: "https://docs.google.com/forms/d/e/1FAIpQLSfuXJf8bjE4cYO5f_5g4w-CW0R_LXruvaNG1-veDiEwFh0fEg/viewform?usp=pp_url",
                   type: "POST",
                   data: { "entry.1403582438": name, "entry.920640653": email, "entry.1631209175": contact, "entry.1757207008": category_id, "entry.669414687": inquiry},
                   dataType: "xml",
                   statusCode: {
                        0: function() {

                        },
                        200: function() {

                        }
                   }
                });

         e.preventDefault();
        });
      });
    </script>

お名前
メールアドレス
お電話番号

お問合わせの種類

無料体験 料金 入会について その他 お問合わせ内容
home.php中的ajax部分

<div id='googleForm'>
            <form>

              <div class='item'>
                <label class='label'>お名前</label>
                <input class='inputs' type='text' name='entry.1403582438' required>
              </div>

              <div class='item'>
                <label class='label'>メールアドレス</label>
                <input class='inputs' type='email' name='entry.920640653' required>
              </div>
              <div class='item'>
                <label class='label'>お電話番号</label>
                <input class='inputs' type='text' name='entry.1631209175' required>
             </div>

              <div class='item'>
                <p class='label'>お問合わせの種類</p>
                <div class='inputs'>
                <input id='cut' type='radio' name='entry.1757207008' value='1'><label for="cut">無料体験</label>
                <input id='cut-color' type='radio' name='entry.1757207008'  value='2'><label for="cut-color">料金</label>
                <input id='headspa' type='radio' name='entry.1757207008'  value='3'><label for="headspa">入会について</label>
                <input id='other' type='radio' name='entry.1757207008'  value='4'><label for="other">その他</label>

                </div>
              </div>

              <div class='item'>
                <label class='label'>お問合わせ内容</label>
                <textarea class='inputs' name='entry.669414687' required></textarea>
              </div>

              <div class='btn-area'>
                <input type='submit' value='送信'><input type='reset' value='リセット'>
              </div>

            </form>
        </div>
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
    <script>
      $(function() {
        $('#googleForm').submit(function(e){

                let hostUrl = "https://docs.google.com/forms/u/0/d/e/1FAIpQLSfuXJf8bjE4cYO5f_5g4w-CW0R_LXruvaNG1-veDiEwFh0fEg/formReisponse";
                let name = $('input:text[name="entry.1403582438"]').val();
                let email = $('input[name="entry.920640653"]').val();
                let contact = $('input:text[name="entry.1631209175"]').val();
                let category_id = $('input:radio[name="entry.1757207008"]:checked').val();
                let inquiry = $('textarea[name="entry.669414687"]').val();
                $.ajax({
                   url: "https://docs.google.com/forms/d/e/1FAIpQLSfuXJf8bjE4cYO5f_5g4w-CW0R_LXruvaNG1-veDiEwFh0fEg/viewform?usp=pp_url",
                   type: "POST",
                   data: { "entry.1403582438": name, "entry.920640653": email, "entry.1631209175": contact, "entry.1757207008": category_id, "entry.669414687": inquiry},
                   dataType: "xml",
                   statusCode: {
                        0: function() {

                        },
                        200: function() {

                        }
                   }
                });

         e.preventDefault();
        });
      });
    </script>

$(函数(){
$(“#谷歌表单”).submit(函数(e){
让hostUrl=”https://docs.google.com/forms/u/0/d/e/1FAIpQLSfuXJf8bjE4cYO5f_5g4w-CW0R_LXruvaNG1-veDiEwFh0fEg/formReisponse";
让name=$('input:text[name=“entry.1403582438”]').val();
让email=$('input[name=“entry.920640653”]').val();
let contact=$('input:text[name=“entry.1631209175”]).val();
让category_id=$('input:radio[name=“entry.1757207008”]:checked').val();
let inquiry=$('textarea[name=“entry.669414687”]”)val();
$.ajax({
url:“https://docs.google.com/forms/d/e/1FAIpQLSfuXJf8bjE4cYO5f_5g4w-CW0R_LXruvaNG1-veDiEwFh0fEg/viewform?usp=pp_url",
类型:“POST”,
数据:{“entry.1403582438”:姓名,“entry.920640653”:电子邮件,“entry.1631209175”:联系人,“entry.1757207008”:类别id,“entry.669414687”:查询},
数据类型:“xml”,
状态代码:{
0:函数(){
},
200:函数(){
}
}
});
e、 预防默认值();
});
});
我想用ajax向Google表单提交post请求

我之所以想使用ajax,是因为我希望在提交post请求时网页不会转换为Google表单

问题是当提交请求时,总是会出现一些错误,如控制台面板上出现的以下错误

我不知道该怎么解决这个问题

如果你能分享你的知识,我会非常高兴。

问题解决了。 问题是我给url变量设置了错误的值。 更正为适当的一个,post请求已正确提交到谷歌表单

另外,当将“数据类型”从“xml”更改为“jsonp”时,解决了以下一直存在的错误

''' CORS策略已阻止从源“”访问“”处的XMLHttpRequest:请求的资源上不存在“访问控制允许源”标头。
“”“

您的服务器不允许访问google链接,您使用的是哪台服务器?apache?谢谢你的评论!是的,我在使用apache。请在文件夹中创建一个文件“.htaccess”,并将其放入其中(标题集Access Control Allow Origin“*”),然后重新启动apache并进行测试,显示出现的错误。我认为允许访问错误发生在google form的服务器上,而不是我这边。因为我向google form server提交了post请求,并收到以下错误:“从源站“”访问“”处的XMLHttpRequest已被CORS策略阻止:请求的资源上不存在“访问控制允许源站”标头。”fomer是google form server