I know this question must've been asked various times here but I have not found a solution from all links I could search for. I don't understand how to do this.
I have a form, with 2 textboxes and 1 submit button. The form name is 'form1'
here is what I was using till now:
<script type="text/javascript">
$("#form1").submit(function() {
$.ajax({
type: 'GET',
url: 'response.php',
data: {1: $("#txt1").val(), 2: $("#txt2").val()},
success: function (data) {
$("#update").prepend(data);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
});
});
</script>
'update' is a table.
I am adding a new row to it after the data is parsed in response.php.
Now, the problem is, using AJAX for this is not at all secure. Users can use plugins such as 'Tamper Data' for firefox to mess with these and send any data they want regardless of what they entered. Thus, making me vulnerable to XSS and CSRF attacks.
So I tried a different approach, I set the form's action to response.php.
Now, there are 2 problems in doing that:
The page refreshes.
How can I make the table row prepend via PHP that too in another document? Earlier I was just echoing it and then AJAX prepended the data for me.
"POST"$("#form1").submit(function(e) {e.preventDefault(); [AJAX REQUEST]})or$("#form1").submit(function() { [AJAX REQUEST] return false;});