i have some problems with collecting the data i fetch from database. Dont know how to continue.
What i did so far:
JQ:
$(document).ready(function(){
$('#submit').click(function(){
var white = $('#white').val();
$.ajax({
type:"POST",
url:"page.php",
data:{white:white}
});
});
});
PHP (requested page.php) so far:
$thing = mysql_real_escape_string($_POST["white"]);
..database connect stuff..
$query = "SELECT * FROM table1 WHERE parameter='$thing'";
if($row = mysql_query($query)) {
while (mysql_fetch_array($row)) {
$data[]=$row['data'];
}
}
What i dont know, is how to send out data and receive it with ajax.
What about errors when request is not succesful?
How secure is ajax call against database injection?
Thanks 🙂
You’ll need a
successparameter in$.ajax()to get a response once a call is madeWhatever you echo (HTML tags or variables) in
page.phpwill be shown in the element whose ID issomeID, preferable to keep the element a<div>In
page.php, you can capture the value entered in the input element by using$_POST['white']and use it to do whatever DB actions you want to