Sending data to php page using ajax and get response and show in fields
11,576
Yes it is possible. Take a look at this example.
On your page.php
<?php
echo $_POST["fld1"];
?>
On your myForm.html. event.preventDefault() is needed, otherwise submit will perform at default and page will be reload.
<script>
$(function(){
$("#submit").click(function(event){
event.preventDefault();
$.ajax({
type:"post",
url:"page.php"
data:$("#form").serialize(),
success:function(response){
alert(response);
}
});
});
});
</script>
<form id="form" method = "post" action = "page.php">
<input type = "text" name = "fld1" id = "fld1" />
<input type = "text" name = "result1" id = "result1" value = "value_from_php_page" disabled />
<input type="submit" value="Submit" id="submit">
</form>
Related videos on Youtube
Author by
Mubin
Linked to dev industry from last 8 years. trying to help over here at SO and always trying to learn new technologies.
Updated on September 17, 2022Comments
-
Mubin over 1 year
I've the following form which I want to post to page.php and want to get result calculted on page.php and want to show that data in the table boxes using AJAX or JQUERY, is this possible? If yes so let me know please. I don't want to refresh the page as I want to be filled all data on single page and want to display all results on that page(IN table cells as user input data in one table and it will update its response).
<form method = "post" action = "page.php"> <input type = "text" name = "fld1" id = "fld1" /> <input type = "text" name = "result1" id = "result1" value = "value_from_php_page" disabled /> ... </form>
-
Mubin over 10 yearsCan you provide me demo pls
-
sravis over 10 years@MubinKhalid Have you tried writing some code for it? or at least tried learning it?
-