ajax能返回,但是不刷新当前页面。要强制刷新才管用

legendnan 2014-03-12 12:21:09

<script type="text/javascript">
$(document).ready(function() {
$(".quxiao").each(function(){
$(this).click(function(){
quxiao($(this));
})
})
});
function quxiao(obj){
var oid = $(obj).val();
var oid = $(obj).parent().next().children(".oid").val();//获取节点
//alert(oid);
$.ajax({ //一个Ajax过程
type: "post", //以post方式与后台沟通
url : "xgkcg.php", //与此php页面沟通
dataType:'json', //从php返回的值以 json方式 解释
data: {oid:oid},
success: function()
{ //如果调用php成功
alert("成功取消订单!");
}
});
}
</script>


php文件

require_once("config.php");
header('content-type:application/json');
$oid=$_POST['oid'];
$sql="delete from `djs_shops_orders` where oid = '$oid'";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);

html

<td><input id="quxiao" class="quxiao" type="button" value="取消"></td>
<td><input type="hidden" class="oid" id="oid" value="<?php echo $v['orderid']; ?>"></td>

我强制刷新当前页面他才会显示出来
...全文
690 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
嘻哈大咖秀 2014-03-12
  • 打赏
  • 举报
回复
ajax是不能自动刷新页面的,可以如下实现
success: function()
        {                              
            alert("成功取消订单!");      
            window.reload();       
        }
或者不刷新的话 调用代码删除
success: function()
        {                              
            alert("成功取消订单!");      
                $(obj).closest('tr').remove();
        }
xuzuning 2014-03-12
  • 打赏
  • 举报
回复
1、你的 xgkcg.php 没有输出 2、你执行的是删除指令,mysql_fetch_row($result) 只会报错
嘻哈大咖秀 2014-03-12
  • 打赏
  • 举报
回复
引用 5 楼 legendnan 的回复:
加上转义字符就不能执行sql语句了。有没有什么更好的办法
你吧$sql打印出来看看 不能执行报什么错误了吗?
legendnan 2014-03-12
  • 打赏
  • 举报
回复
引用 4 楼 microlab2009 的回复:
require_once("config.php");
	header('content-type:application/json');
	$oid = addcslashes($_POST['oid']);//转义字符
	$sql = "delete from `djs_shops_orders` where oid = '$oid'";
	mysql_query($sql);
	if(mysql_affected_rows() > 0){//影响条数
		return true;
	}else{
		return false;
	}
加上转义字符就不能执行sql语句了。有没有什么更好的办法
嘻哈大咖秀 2014-03-12
  • 打赏
  • 举报
回复
require_once("config.php");
	header('content-type:application/json');
	$oid = addcslashes($_POST['oid']);//转义字符
	$sql = "delete from `djs_shops_orders` where oid = '$oid'";
	mysql_query($sql);
	if(mysql_affected_rows() > 0){//影响条数
		return true;
	}else{
		return false;
	}
legendnan 2014-03-12
  • 打赏
  • 举报
回复
引用 楼主 legendnan 的回复:

<script type="text/javascript">  
	$(document).ready(function() {
      $(".quxiao").each(function(){
        $(this).click(function(){
          quxiao($(this)); 
        })
      })
    });
    function quxiao(obj){
      var oid = $(obj).val();
		var oid = $(obj).parent().next().children(".oid").val();//获取节点
		//alert(oid);
		$.ajax({                        //一个Ajax过程  
		type: "post",                   //以post方式与后台沟通  
		url : "xgkcg.php",				//与此php页面沟通  
		dataType:'json',                //从php返回的值以 json方式 解释  
		data: {oid:oid}, 
		success: function()
		{								//如果调用php成功    
		alert("成功取消订单!");             
		}
		});
}   
</script>
php文件

	require_once("config.php");
	header('content-type:application/json');
	$oid=$_POST['oid'];
	$sql="delete from `djs_shops_orders` where oid = '$oid'";
	$result = mysql_query($sql);
	$row = mysql_fetch_row($result);
html

<td><input id="quxiao" class="quxiao" type="button" value="取消"></td>
					<td><input type="hidden" class="oid" id="oid" value="<?php echo $v['orderid']; ?>"></td>
我强制刷新当前页面他才会显示出来
引用 2 楼 microlab2009 的回复:
ajax是不能自动刷新页面的,可以如下实现
success: function()
        {                              
            alert("成功取消订单!");      
            window.reload();       
        }
或者不刷新的话 调用代码删除
success: function()
        {                              
            alert("成功取消订单!");      
                $(obj).closest('tr').remove();
        }
php的代码我又写成这样了,感觉挺不规范的,不知该如何改进?

	require_once("config.php");
	header('content-type:application/json');
	$oid=$_POST['oid'];
	$sql="delete from `djs_shops_orders` where oid = '$oid'";
	$result = mysql_query($sql);
	if($result){
		return true;
	}else{
		return false;
	}

20,398

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧