AJAX不发送帖子数据

I have this problem where i cant get any response from the .php that ajax is sending data to. its supposed to run a insert on mysql, i tried putting the query manually to see if it works and it does.

Here's the function that sends ajax

function Continue(SLAatendida) {
var url = window.location.pathname;
var id = url.substring(url.lastIndexOf('/')+ 1);
    console.log(SLAatendida);
    console.log(id);
    $.ajax({
    type: 'POST',
    url: 'ws.php',
    data: { 
        'id': id,
        'sla_atendida': SLAatendida
    },
    success: function(msg){
        console.log(msg);
    }
    });

And the php file thats supposed to run the query (ws.php)

    <?php
session_start();

header('Access-Control-Allow-Origin: *');
header('Content-type: text/html; charset=UTF-8');

include('debug.php');
include('../antest/dbconnect.php');

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$debug_to_console("ws");

$id = $_POST["id"];
$SLAatendida = $_POST["sla_atendida"];

$sql_upd_sla = "INSERT INTO sla (id, sla_atendida) VALUES ('$id','$SLAatendida')";
$data = $conn->query($sql_upd_sla);
if($conn->query($sql_upd_sla))
{
    echo "Registro efetuado com sucesso";
} else {
    echo "Houve um erro";
    die();
}
?>

Both console.log returns the right values from the var.

dream989898
dream989898 是的,我运行所有的检查和PHP安装正确,即使我使用7.2和是的,不使用短标签
11 个月之前 回复
dongzhuang1923
dongzhuang1923 不。它应该返回一条消息,而不是代码。请参阅stackoverflow.com/questions/5121495/...
11 个月之前 回复
douzhajie7168
douzhajie7168 是的,我错了不发送它,检查网络选项卡和ws.php是否存在,但是var_dump和echo尝试都没有返回任何值,我也注意到console.log(msg)返回页面中的所有代码那应该发生吗?
11 个月之前 回复
dqoeghe9452
dqoeghe9452 你确定它不发送它吗?提交时,请检查DeveloperConsole的“网络”选项卡,然后查看“请求”选项卡以查看其中的内容。也做var_dump($_POST);在PHP中查看它包含的内容。如果一切都在那里,echo$sql_upd_sla;看看包含什么。
11 个月之前 回复

1个回答



在URL属性中,您必须放置 http: // localhost 或您在本地计算机中配置的URL + ws.php </ p>

示例:</ p>

  url:  'http://localhost/ws.php',
</ code> </ pre>
</ div>

展开原文

原文

In the URL attribute you must put the http://localhost or the url your have configure in your local machine + ws.php

example:

url: 'http://localhost/ws.php',

doudi7782
doudi7782 哦,这就是问题,非常感谢你的帮助!
11 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问