jquery ajax 提交后返回数据失败
时间:2009-05-22
来源:互联网
var categro = $("#cate_name").val();
var usergro = $("#user_name").val();
$.ajax({ //ajax 方式
type: "post",
url:"lib/notepad_ajax.php?method=addcate",
data:"cate_name=" + categro + "&user_name=" + usergro,
success:function(msg){
alert(msg);
}
});
$.post("lib/notepad_ajax.php?method=addcate",{cate_name:categro,user_name:usergro} ,function(data){alert(data)}); //post方式
$.get("lib/notepad_ajax.php?method=addcate",{cate_name:categro,user_name:usergro},function(data){alert(data)}); //get方式
服务器端
<?
if(trim($_GET['method']) == 'addcate'){//添加分类
echo "12313213212"."<br>\n";
echo $_POST['cate_name']."<br>\n";
echo "分类添加成功!";exit;
三种方式都试过了,服务器端都没有返回数据,用firebug 查看,请求数据成功发送,但返回失败。。。在ie7中有时返回成功,有时返回失败,firefox中总是返回失败,请问是什么原因引起,jquery 版本为1.3.2
data是个map,不需要自己构造string。因为post并不是用&连接各个参数的。
此外,客户端设定的是post,服务器端为什么用$_GET['method']
var usergro = $("#user_name").val();
$.ajax({ //ajax 方式
type: "post",
url:"lib/notepad_ajax.php?method=addcate",
data:"cate_name=" + categro + "&user_name=" + usergro,
success:function(msg){
alert(msg);
}
});
$.post("lib/notepad_ajax.php?method=addcate",{cate_name:categro,user_name:usergro} ,function(data){alert(data)}); //post方式
$.get("lib/notepad_ajax.php?method=addcate",{cate_name:categro,user_name:usergro},function(data){alert(data)}); //get方式
服务器端
<?
if(trim($_GET['method']) == 'addcate'){//添加分类
echo "12313213212"."<br>\n";
echo $_POST['cate_name']."<br>\n";
echo "分类添加成功!";exit;
三种方式都试过了,服务器端都没有返回数据,用firebug 查看,请求数据成功发送,但返回失败。。。在ie7中有时返回成功,有时返回失败,firefox中总是返回失败,请问是什么原因引起,jquery 版本为1.3.2
[ 此帖被sclzjl在2009-05-22 16:35重新编辑 ]
描述:firebug查看
图片:
'700')this.width='700';if(this.offsetHeight>'700')this.height='700';" title="Click Here To EnLarge">
图片:
'700')this.width='700';if(this.offsetHeight>'700')this.height='700';" title="Click Here To EnLarge">
描述:firebug查看
图片:
'700')this.width='700';if(this.offsetHeight>'700')this.height='700';" title="Click Here To EnLarge">
图片:
'700')this.width='700';if(this.offsetHeight>'700')this.height='700';" title="Click Here To EnLarge">
描述:firebug查看
图片:
'700')this.width='700';if(this.offsetHeight>'700')this.height='700';" title="Click Here To EnLarge">
图片:
'700')this.width='700';if(this.offsetHeight>'700')this.height='700';" title="Click Here To EnLarge">
描述:firebug查看
图片:
'700')this.width='700';if(this.offsetHeight>'700')this.height='700';" title="Click Here To EnLarge">
图片:
'700')this.width='700';if(this.offsetHeight>'700')this.height='700';" title="Click Here To EnLarge">
描述:ie中返回
图片:
设置下dataType和服务器端的content-type,并注意下charset图片:
data是个map,不需要自己构造string。因为post并不是用&连接各个参数的。
此外,客户端设定的是post,服务器端为什么用$_GET['method']
作者: sclzjl 发布时间: 2009-05-22
var categro = $("#cate_name").val();
var usergro = $("#user_name").val();
$.ajax({ //ajax 方式
type: "post",
url:"lib/notepad_ajax.php?method=addcate&cate_name=" + categro + "&user_name=" + usergro,
success:function(msg){
alert(msg);
}
});
-------------
直接把data加在url后面试一下
var usergro = $("#user_name").val();
$.ajax({ //ajax 方式
type: "post",
url:"lib/notepad_ajax.php?method=addcate&cate_name=" + categro + "&user_name=" + usergro,
success:function(msg){
alert(msg);
}
});
-------------
直接把data加在url后面试一下
作者: keakon 发布时间: 2009-05-22
那就不叫post了
post会把提交的数据进行编码的
post会把提交的数据进行编码的
作者: caedmon 发布时间: 2009-05-23
复制代码
|
作者: keakon 发布时间: 2009-05-23
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28