会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132358个问题

http://iwenwiki.com/api/covid19-server/ 这个备用接口用不了,没解决跨域问题啊

老报错

1667550976259.png

WEB前端全系列/第五阶段:前后端交互/网络请求AJAX 46楼
WEB前端全系列/第五阶段:前后端交互/网络请求AJAX 47楼
WEB前端全系列/第五阶段:前后端交互/服务器与数据库交互 48楼
WEB前端全系列/第五阶段:前后端交互/服务器 49楼
WEB前端全系列/第五阶段:前后端交互/服务器 50楼
WEB前端全系列/第五阶段:前后端交互/网络请求AJAX 51楼

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Update</title>
    <script src="./jquery-3.6.0.min.js"></script>
</head>

<body>
    <input type="text"><button>提交</button>
</body>
<script>
    var button = document.querySelector("button");
    button.addEventListener("click", function() {
        var addedAge = document.querySelector("input").value;
        $.ajax({
            type: 'get',
            url: "http://localhost/allSim/setAddedAge.php",
            data: {
                addedAge: addedAge
            },
            success: function(data) {
            console.log(data);
                /*data = JSON.parse(data) ;*/
                if (data.msg) {
                    console.log(data.msg);
                } else {
                    console.log(data);
                }
            }
        });
    })
</script>

</html>

php:


<?php

    $addedAge=$_get["addedAge"];

    $con=mysqli_connect("localhost","root",'','sim4_history_saves_sim');

    if($con){

       mysqli_query($con,"set names utf8");

       $sql="update gameupdateddata set value=$addedAge where item=addedAge" ;

       $result=mysqli_query($con,$sql);

       if($result->num_rows>0){

         $data=mysqli_fetch_all($result,MYSQLI_ASSOC);

         mysqli_close($con);

         echo json_encode($data);

       }else{

        echo json_encode(array("msg"=>"查询结果不存在"));

       }

    }else{

        echo json_encode(array("msg"=>"数据库连接错误!"));

    }

   

 

 

 ?>

我想实现一个改数据的功能

html文件是一个输入框和按钮,输入要改的值,点击按钮,更改数据库的值

数据库的值没有被改,我把data打印出来是

<br />

<b>Warning</b>:  Undefined variable $_get in <b>C:\xampp\xampp\htdocs\allSim\setAddedAge.php</b> on line <b>2</b><br />

<br />

<b>Warning</b>:  Trying to access array offset on value of type null in <b>C:\xampp\xampp\htdocs\allSim\setAddedAge.php</b> on line <b>2</b><br />

<br />

<b>Fatal error</b>:  Uncaught mysqli_sql_exception: 由于目标计算机积极拒绝,无法连接。 in C:\xampp\xampp\htdocs\allSim\setAddedAge.php:3

Stack trace:

#0 C:\xampp\xampp\htdocs\allSim\setAddedAge.php(3): mysqli_connect('localhost', 'root', '', 'sim4_history_sa...')

#1 {main}

  thrown in <b>C:\xampp\xampp\htdocs\allSim\setAddedAge.php</b> on line <b>3</b><br />


update.html:31 <br />

<b>Warning</b>:  Undefined variable $_get in <b>C:\xampp\xampp\htdocs\allSim\setAddedAge.php</b> on line <b>2</b><br />

<br />

<b>Warning</b>:  Trying to access array offset on value of type null in <b>C:\xampp\xampp\htdocs\allSim\setAddedAge.php</b> on line <b>2</b><br />

<br />

<b>Fatal error</b>:  Uncaught mysqli_sql_exception: 由于目标计算机积极拒绝,无法连接。 in C:\xampp\xampp\htdocs\allSim\setAddedAge.php:3

Stack trace:

#0 C:\xampp\xampp\htdocs\allSim\setAddedAge.php(3): mysqli_connect('localhost', 'root', '', 'sim4_history_sa...')

#1 {main}

  thrown in <b>C:\xampp\xampp\htdocs\allSim\setAddedAge.php</b> on line <b>3</b><br />

我不太明白错在哪里了

WEB前端全系列/第五阶段:前后端交互/网络请求AJAX 54楼
WEB前端全系列/第五阶段:前后端交互/网络请求AJAX 55楼
WEB前端全系列/第五阶段:前后端交互/服务器与数据库交互 56楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637