views:

279

answers:

1

I know, silly question but what do I put where?

I post data to a php processing page:

$insert = mysql_query('INSERT INTO '.$table.' ('.substr($addfields,0,-1).') VALUES  ('.substr($addvals,0,-1).')');

a bit like that

I want to have

if($insert): echo 'Message 1'; else: echo 'message2'; endif;

what do I do in my success: function()? to display the message in <div id="result"></div>

I have tried

success: function() {
$(#result).html(html);
}

etc. but it doesn't work.

It may complicate things in that I want to actually use .load() into #result based on the "message" from the php

+1  A: 

Assuming that your $.ajax() request is using dataType: 'html' (or the default, which will intelligently guess) your success function will receive the returned text as its first parameter:

$.ajax({
  url: '/mypage.php',
  dataType: 'html',
  success: function(data) {
    $('#result').html(data);
  }
});

Should take whatever HTML your mypage.php dumps out, and replace the contents of the <div id="result"> on the page just fine!

I have assembled a jsfiddle demo for you to look at.

gnarf