0

I'm trying to retrive some code from a php method using ajax, when a person click a div.

HTML

<div class="contenitore">
    <div>
        <input class="idCommento" value="//some number">
    </div>
    <div>
        <p class="vediRisp">Create text</p>
    </div>
</div>
<div class="contenitore">
    <div>
        <input class="idCommento" value="//some number">
    </div>
    <div>
        <p class="vediRisp">Create text</p>
    </div>
</div>

PHP (lib/Users.class.php)

Class Users{
    public function dammi_i_commenti(arguments){
        return '<div>code</div>';
    }
}

(lib/ottieniCose.php)

require('Users.class.php');
$login = New Users;

$GLOBAL['current'] == $_GET['adesso'];
print $login->dammi_i_commenti();

AJAX

$(".vediRisp").on('click', function() {
    var mh = $(this).parentsUntil(".contenitore").find(".idCommento");
    var eeeh = mh.val();
    $.ajax({
        url: "lib/ottieniCose.php",
        type: "GET",
        data: {
            adesso: eeeh,
        },
    })
    .done(function() {
        console.log("success");
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });
});

When i click the .vediRisp in the console i can read success, then complete, so I'm thinking that the click and ajax function work, but the page doesn't seem to update its content therefore i think that i'm not calling the method correctly. Anyway if i try to write var_dump("stuff") or print_r("stuff") in the ottieniCose.php file i get absolultely no result at all, and my guess is that i'm not using the ajax function correctly, or the ottieniCose.php file isn't called. Any help?

1 Answer 1

1

You need to add the response to the page using jquery.

.done(function(response) {
        console.log("success");
        $("#<some div id>").html(response)
    })

Simply printing it on the php script wont add it to he page.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.