weixin_33705053 2017-11-24 00:20 采纳率: 0%
浏览 30

PHP AJAX重定向不起作用

My goal is to get via ajax the return of a php file. I have the following HTML form, I put the image to not break the indentation of the code.

http://prntscr.com/hegz9y

My function:

<script type="text/javascript">
function pedir(){

            $.ajax({
                method: "post",
                url: "atualiza.estoque.php",
                data: $("#form").serialize(),
            success: function(data){
                       alert("Busca efetuado com sucesso !");
            }


        });
}
</script>

My PHP:

 <?php
    include "../php/bddata.php";
    header('Content-type: application/json; charset=utf-8'); 

// Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    $sql="SELECT * FROM produto";
    $result=$conn->query($sql);

    while($row=$result->fetch_assoc()){
        echo "id: " . $row["idProduto"]. " - Name: " . $row["nome"];
    }
    echo json_encode(['success' => true]);
    $conn->close();
?> 

I can not see what's wrong with this code, I'd be grateful if anyone could help me. Sorry for my English, I'm not native.

  • 写回答

1条回答 默认 最新

  • 乱世@小熊 2017-11-24 00:27
    关注

    Use type not method

    $.ajax({
        type: "post", // this one
        url: "atualiza.estoque.php",
    
    评论

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗