ajax和php错误:未定义的索引:在我的例子中是userid
ajax and php error : Undefined index: userid in my case
哪里出了问题?
$http({
url: "php/loaduser.php?userid=user_id",
method: "GET",
data: {'user_id':'1'}
}).success(function(data, status, headers, config) {
mydata = [];
mydata = data;
console.log(mydata);
}).error(function(data, status, headers, config) {
// $scope.status = status;
alert(status);
});
我的php
echo $_GET['user_id'];
它返回未定义的索引:user_id
您的呼叫应该像一样
$http({
url: "php/loaduser.php",
method: "GET",
data: {'user_id':'1'}
})
或者你可以使用
$http({
url: "php/loaduser.php?user_id=" + user_id,
method: "GET"
})
在第二种方法中,您直接通过url传递user_id
,而在第一种方法中则以可变方式发送
您正在发送字符串user_id
。
url: "php/loaduser.php?userid=user_id"
删除最后一个查询参数。
更改为:
url: "php/loaduser.php"
试试这个--
$.ajax({
type:"GET",
url:"php/loaduser.php",
data: {'user_id':1}
success:function(data, status, headers, config){
ydata = [];
mydata = data;
console.log(mydata);
}),
error(function(data, status, headers, config) {
// $scope.status = status;
alert(status);
}
});
URL中的键错误:您需要将其从userid
更改为user_id
。然后,你不需要设置数据属性,你可以在你的URL中包括这样的参数:
url: "php/loaduser.php?user_id=" + '1'
相关文章:
- 为什么不't Javascript对我的输入值进行了一些重新检查
- 可以't让我的if语句处理js中的html表单输入
- 我的单元测试选项是什么
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 我的职位回报太快了,如何做出承诺
- 我的jQuery插件参数没有正确启动,遇到了问题
- 如何识别我的网站中的慢速设备
- 如何将JSON数据导入我的ejs模板
- JQuery添加元素需要在我的js之前再次添加JQuery脚本
- 知道为什么我的旋转木马不会自动更改图片吗
- 我的模板未被解析
- 无法将数据从firebase获取到我的html页面
- 角度图表;t显示在我的页面中
- 我的AngularJS表达式没有'不起作用
- 将电视直播频道从网站嵌入我的网站
- /undefined在我的404错误日志中多次出现
- 为什么我的d3.jsselectAll+过滤器没有过滤
- 元素在我的代码中不会.fadeTo.Don'I don’我不知道;s错误的JavaScript、JQuery、H
- 我的javascript for循环不起作用
- ajax和php错误:未定义的索引:在我的例子中是userid