currently have this code activated by a html button:
x
function popup() {
var group = prompt("Please enter group name");
if (group != null || group != "") {
window.location.href = "template.php?groupid=" + group; //groupid
}
}
i wanna send the value of group in a sql query in some way, so it can creaty a unique id and use that as my groupid. i think i have to use ajax, but im unable to find a tutorial for this.
Advertisement
Answer
- Add jquery.js reference (e.g. jquery-1.10.2.js)
- use ajax in place of your original call to template.php
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
function popup() {
var group = prompt("Please enter group name");
if (group != null || group != "") {
// window.location.href = "template.php?groupid=" + group; //groupid
$.ajax({
type: "POST",
dataType: 'text',
url: "template.php?groupid" + group,
success: function(response){
//if request if made successfully then the response represent the data
// do something after the ajax is done. e.g. alert(response)
//the response can be your groupid which the template.php echo execution
}
});
}
}
</script>
For example in your template.php:
<?php
// include "db.php";
/// process the groupid=group
//// further processing to generate the unique $groupid
echo $groupid;
?>