未定义索引:ajax POST和/或php脚本错误?

编程入门 行业动态 更新时间:2024-10-27 09:45:04
本文介绍了未定义索引:ajax POST和/或php脚本错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将ajax POST发送到php文件,但是php文件发送了未定义索引"的通知,并且php文件似乎从未收到我试图发送的值.我一直在寻找为什么它不能正常工作的答案,所以希望有人可以给我一些见识.

I'm trying to send an ajax POST to a php file, however the php file sends a notice of "undefined index", and the php file never seems to receive the value i'm trying to send it. I've been searching for the answer to why this isn't working correctly, so hopefully someone can give me some insight.

我的javascript函数从html接收一个值,并接收正确的值. (在这种情况下为"1")

My javascript function receives a value from the html, and receives the correct value. (it's "1" in this case)

function deleteMediaFromDatabase(val) { $.ajax({ url: 'deleteMediaFromDatabase.php', data: {vals : val}, type: 'post', success: function(output) { alert(output); }, error: function(request, status, error){ alert("Error: Could not delete"); } }); }

这是我的php文件的一部分,应该会收到该帖子:

Here is part of my php file that should receive the post:

<?php ini_set("display_errors", "On"); error_reporting(E_ALL); $val = $_POST["vals"]; // create connection $con = mysqli_connect(<stuff you don't care about>); error_log($val . ' is the value', 3, "./error.log"); ?>

我在,但是从php收到此错误消息:

I am, however getting this error message from php:

注意:未定义索引:vals in /xxx/xxx/htdocs/AdminPanel/deleteMediaFromDatabase.php,第9行

Notice: Undefined index: vals in /xxx/xxx/htdocs/AdminPanel/deleteMediaFromDatabase.php on line 9

而且我的JavaScript总是在以下错误中输出警报:错误:无法删除"

And my javascript always outputs the alert in the error: "Error: Could not delete"

我知道这个问题已经被问过很多次,但是,除非我跳过一些小东西,否则我的代码对我来说看起来是正确的. (但并非总是如此...)

I know this question has been asked and answered many times, however unless I'm skipping over something small, my code, to me, looks correct. (but doesn't it always...)

推荐答案

jquery的语法错误.您错过了数据的语法.这应该是这样的-

There is error in syntax of jquery.. You missed out syntax of data. This should be like this-

function deleteMediaFromDatabase(val) { $.ajax({ url: 'deleteMediaFromDatabase.php', data: {'vals' : val}, type: 'post', dataType:'json', success: function(output) { alert(output); }, error: function(request, status, error){ alert("Error: Could not delete"); } }); }

更多推荐

未定义索引:ajax POST和/或php脚本错误?

本文发布于:2023-10-11 17:42:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1482383.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   索引   错误   未定义   POST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!