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

WBOY
Release: 2016-06-13 11:53:03
Original
1590 people have browsed it

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

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


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

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

我强制刷新当前页面他才会显示出来
------解决方案--------------------
1、你的 xgkcg.php 没有输出
2、你执行的是删除指令,mysql_fetch_row($result) 只会报错

------解决方案--------------------
ajax是不能自动刷新页面的,可以如下实现
success: function()<br />        {                              <br />            alert("成功取消订单!");      <br />            window.reload();       <br />        }
Copy after login

或者不刷新的话 调用代码删除
success: function()<br />        {                              <br />            alert("成功取消订单!");      <br />                $(obj).closest('tr').remove();<br />        }
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template