re1man
re1man

Reputation: 2367

Receiving result from .ajax function in jQuery

I have this code :

$.ajax({
    type: "POST",
    url: "tosql.php",
    data: {
        content, content
   }
});

I was wondering how I could get a callback from tosql.php (the result) and add that html to div class = "content"

Upvotes: 1

Views: 69

Answers (3)

karim79
karim79

Reputation: 342765

Do that within the success callback:

$.ajax({
    type: "POST",
    url: "tosql.php",
    data: {
        content: content
    },
    success: function(html) {

        // you said 'add' so I'm assuming '.append'
        // if you meant fill/replace then use `.html(html);`
        $("div.content").append(html);
    }
});

Also (if it's not a typo on your part), object property names and values are separated by the colon:

    data: {
        content: content
    },

and not the comma:

    data: {
        content, content
    },

Upvotes: 3

Praveen Prasad
Praveen Prasad

Reputation: 32127

$.ajax({
    type: "POST",
    url: "tosql.php",
    data: {
        content: content
   },
   success:function(data)
   {
      jQuery('#target').html(data);
    }
});

Upvotes: 0

banzai
banzai

Reputation: 151

ok maybe this code is true and solve your problem.. data : mydata *success: resultdt*

var mydata = $(".form").serialize();
$.ajax({
    type: "POST",
    url: "tosql.php",
    data: mydata,
    sucess: resultdt
});


function resultdt(data,status){
   data=$.trim(data);
   $(".c").html(data);
}

Upvotes: 0

Related Questions