gsamaras
gsamaras

Reputation: 73366

See what php page of action returns

For example, in an AJAX call, I would do that:

$.ajax({
        type: ...,
        url: bla.php,
        data: ..,
        success: function(msg) {
            alert(msg);
            ...

which would give me what bla.php would return, for example by an echo.

How to do that with my form too?


So, now my form looks like this:

<form action="url.php" method="post">
  Slot:<input type="text" name="slot" value="<?=$varSlot;?>">
  <input type="submit" name="formSubmit" value="Submit">
</form>

How can I see what url.php returns?

Upvotes: 0

Views: 42

Answers (1)

marcoFSN
marcoFSN

Reputation: 125

first of all, understand that your form is gonna be redirected to "url.php", you are going to tell the browser to send that form to that page, so it will redirect to that page.

Possibilities 1 - let it be like it is, and in the "url.php" put the code you wanna show, an processe wathever you want

2 - Use ajax instead and retrieve wathever you want to be from "url.php"

3 - If you just want to process the data and get back to the same page you are right now, user redirect("page.php") and it will redirect to that page once it's finished.

4 - Use something like this to make use of ajax and return wathever is in the "url.php" files

<form action="url.php" method="post" id="formName">
    SLOT:<input type="text" name="slot" value="<?=$varSlot;?>">
    <input type="submit" name="formSubmit" value="Submit">
</form>
<script>
    $(function(){
        $("#formName").submit(function(e){
            $("#id-of-div-or-something").load("url.php");
            e.preventDefault();
        });
    });    
</script>

NOTE: note that the submit function is pointing to a form id, and the "load" point wherever you want to put the codeor wathever is in the other "url.php" page.

Hope it helps

Upvotes: 3

Related Questions