python小菜 2017-06-14 21:45 采纳率: 0%
浏览 35

AJAX不提交?

I have this code:

var just = $("#just").val();
var id = $("#id").val();

$.ajax({
    type: "POST",
    url: "cod_ajax/just.php",
    data: "id="+id+"&just="+just,
    cache: false,
    success:function(e){
      alert("Success");
    } 
});

And I have this in cod_ajax/just.php

require "../../db.php";

if (isset($_POST['id'])) {

    $update = mysqli_query($db, "UPDATE table SET just1 = '1', just2 = '".$_POST['just']."' WHERE id = '".$_POST['id']."'") or  die(mysqli_error());

    if ($update) {
        echo "Success!";
    } else {
        echo "Error :(";
    }
}

The SQL code is all acording to database, the db require is okay too, but something seems to not work. I tried to erase one of the data provived by AJAX, like the id but it didn't work anyway nor the just2.

Also checked if both variables where empty or not unexistent but both have information in them.

MORE INFORMATION

I ran this on local server, no errors on console, alert(e) gave me success, all Jquery is included in page.

  • 写回答

2条回答 默认 最新

  • weixin_33720956 2017-06-14 22:35
    关注

    Try to store first variables from post then use in query. So

    $id =  $_POST["id"];
    

    Same for others. Also you might find useful to send data at least as url encoded.

    And then put in query.

    评论

报告相同问题?

悬赏问题

  • ¥15 vue3加ant-design-vue无法渲染出页面
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序