How to put the return of Ajax [form] inside a div?

Asked

Viewed 493 times

1

$.ajax({
    url: 'executa.php',
    type: 'POST',
    data: {emailDestino: emailDestino},
    dataType: 'html',
    success: function(data) {
        $('#notifyInscrito').appendTo(data);
    }   
});

I’m going to the file room executa.php via ajax with an email, and making a query to assemble an HTML with the returned data, and I want to put this complete HTML inside the div #notifyInscrito. Which is a lightbox that soon after will send an email to the record of the returned data.

I tried to make a $('#notifyInscrito').appendTo(data) in order for it to return the form from within the executa.php and insert into the div but it didn’t work.

Question: How to get HTML from executa.php and place inside the div #notifyInscrito?

  • Place the file information executa.php

  • The dataType has Default = String, remove the dataType to treat it as plain text, or change to text.

  • use the function .html() instead of .appendTo()

1 answer

4

The "date" that is returned to you is an object, should be read as data.algumacoisa or data['algumacoisa'].

Try to use a function in executa.php that returns some TEXT to you, because you have defined an HTML as dataType, i.e.: Text.

You can make this following code:

$.ajax({
    url: 'executa.php',
    type: 'POST',
    data: {emailDestino: emailDestino},
    dataType: 'html',
    success: function(data) {
        $('#notifyInscrito').html(data.algumacoisa);
    }   
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.