admin管理员组

文章数量:1323715

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>

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>
Share Improve this question asked Oct 6, 2013 at 2:23 MubinMubin 4,4555 gold badges36 silver badges56 bronze badges 3
  • Yes, this is possible. api.jquery./jQuery.post – David Link Commented Oct 6, 2013 at 2:31
  • 1 Can you provide me demo pls – Mubin Commented Oct 6, 2013 at 2:53
  • 1 @MubinKhalid Have you tried writing some code for it? or at least tried learning it? – sravis Commented Oct 6, 2013 at 2:54
Add a ment  | 

1 Answer 1

Reset to default 5

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>

本文标签: javascriptSending data to php page using ajax and get response and show in fieldsStack Overflow