Py学习  »  Jquery

jquery-post()方法获取“未找到”错误

hamed • 5 年前 • 1364 次点击  

我想给我的 submit.php 通过jquery发布和接收响应。

提交文件 index.html 在网站根目录和 script.js 在“js”文件夹中。

我的 索引文件 :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<body>
<input id="email" type="email" placeholder="  Email"><br>
<a href=""><button id="submit-btn">send</button></a>
<script
  src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous">
</script>
<script src="js/script.js"></script>
</body>
</html>


我的 JScript :

$(document).ready(()=>{
    $("#submit-btn").click(()=>{
        $.post("../submit.php", { user_email: $("#email").val()})
            .done((data)=>{
                alert(data);
            })
            .fail((xhr, status, error)=>{
                alert(error);
            });
    });
});

我的 提交文件 :

<?php
$email = (isset($_POST['user_email']) ? $_POST['user_email'] : "nothing");
echo $email;

我希望输出是我的电子邮件地址,但实际输出是 not found . 我想我的请求失败了

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/33752
 
1364 次点击  
文章 [ 1 ]  |  最新文章 5 年前
Jan
Reply   •   1 楼
Jan    5 年前

因为您说两个文件都在同一个文件夹中,所以不需要 ../ 在你的要求面前。

$.post("../submit.php", { user_email: $("#email").val()})
$.post("submit.php", { user_email: $("#email").val()})