Note that there are some explanatory texts on larger screens.

plurals
  1. POPerform xmlhttprequest and afterwards direct to new url location
    primarykey
    data
    text
    <p>Im new to this ajax and javascript thing. What I want is first to popup a confirm box, if true then perform xmlhttprequest. Afterwards I want to redirect the user to a new page. Here is what I've got.</p> <pre><code>&lt;script type="text/javascript"&gt; function showUser(str) { var r=confirm("Delete this customer?"); if (r==true) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","sletkunde.php?q="+str,true); xmlhttp.send(); } } &lt;/script&gt; &lt;form onclick="showUser(id.value); return false;" &gt; &lt;input type="hidden" value="&lt;?echo $id;?&gt;" name="id"&gt; &lt;input type="button" value="tryk" name="knap"&gt; &lt;/form&gt; &lt;br&gt; &lt;div id="txtHint"&gt;&lt;b&gt;something here&lt;/b&gt;&lt;/div&gt; </code></pre> <p>And here is the sletkunde.php</p> <pre><code>&lt;? $q=$_GET["q"]; $slet = mysql_query("DELETE FROM Kunder WHERE KundeID = '".$q."'"); echo "hey"; // Just to see if it works ?&gt; </code></pre> <p>The confirm box works, the mysql_query works, the echo "hey"; works. But how can I get it to redirect to kunder.php right after all of this (automatically).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload