简体   繁体   English

php代码后重定向回页面

[英]redirect back to page after php code

I am trying the following code to update external content inside a div named "content1" 我正在尝试以下代码来更新名为“ content1”的div中的外部内容

ajax.js: ajax.js:

var ajaxdestination="";

function getdata(what,where) { // get data from source (what)
  try {
    xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
new ActiveXObject("Microsoft.XMLHTTP");
  }
catch (e) { /* do nothing */ }
document.getElementById(where).innerHTML ="<center><img src='loading.gif'></center>"; // Define the destination DIV id, must be stored in global variable (ajaxdestination)
ajaxdestination=where;
xmlhttp.onreadystatechange = triggered; // when request finished, call the function to put result to destination DIV
xmlhttp.open("GET", what);
xmlhttp.send(null);
  return false;
}
function triggered() { // put data returned by requested URL to selected DIV
   if (xmlhttp.readyState == 4) if (xmlhttp.status == 200) 
      document.getElementById(ajaxdestination).innerHTML =xmlhttp.responseText;
}

Inside my div I include 'page1a.php' with php, wich outputs a value from my database and contains a link to 'code1a.php' where I have a php code that updates this value. 在我的div内部,我在PHP中包含“ page1a.php”,从我的数据库输出一个值,并包含指向“ code1a.php”的链接,其中有一个可更新此值的php代码。 (This is just a test and will do more than update a value in the future). (这只是一个测试,将来做的不只是更新值)。

<a href="javascript:void(0)" onClick="getdata('tmpa/code1a.php','content1');">update value</a>

Inside code1a.php where I have a php code that updates my database, after the database has been updated, is there a way to update my div (content1) with 'page1a.php' again? 在code1a.php内部,在数据库更新后,我有一个更新数据库的php代码,是否有办法再次用“ page1a.php”更新div(content1)? I have tried everything i could think of and search the web for a few days, but not found a solution to my problem. 我已经尝试了所有可能想到的方法,并在网上搜索了几天,但没有找到解决我问题的方法。

The script can be found on: http://www.battrewebbsida.se/index2.php 该脚本可以在以下网站找到: http : //www.battrewebbsida.se/index2.php

There are many variants to do this, your solution isn't best to do it, but here's the modified your javascript code, which is that what you want. 有很多变体可以做到这一点,您的解决方案并不是最好的选择,但是这里修改了您的javascript代码,这就是您想要的。

By Javascript 通过Javascript

    var ajaxdestination="";
    var tmpcache = '';
    function getdata(what,where) { // get data from source (what)
      try {
        xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
    new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e) { /* do nothing */ }
    tmpcache = document.getElementById(where).innerHTML;
    document.getElementById(where).innerHTML ="<center><img src='loading.gif'></center>"; // Define the destination DIV id, must be stored in global variable (ajaxdestination)
    ajaxdestination=where;
    xmlhttp.onreadystatechange = triggered; // when request finished, call the function to put result to destination DIV
    xmlhttp.open("GET", what);
    xmlhttp.send(null);
      return false;
    }
    function triggered() { // put data returned by requested URL to selected DIV
       if (xmlhttp.readyState == 4) if (xmlhttp.status == 200) 
          document.getElementById(ajaxdestination).innerHTML =tmpcache;
    }

By PHP 通过PHP

after doing your updates in 'code1a.php' send header location to your first 'page1a.php' file 在“ code1a.php”中执行更新后,将标头位置发送到第一个“ page1a.php”文件

header("Location: ".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'/page1a.php');

NOTE: dont forget about ob_start() at the top of script. 注意:不要忘记脚本顶部的ob_start()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM