2

(I am pretty new to all this.) I have a page where the user can click between different sorting methods of user posts. Depending on which they click the content shown will correspond.

function newContent()
{
  $.ajax({
      url: 'ajax/newcontent.php',
      success: function() 
      {
            $("#content_div").empty().load("ajax/newcontent.php");
      }

      });
}

This is what I have now. But instead of loading the code from the .php page into the #content_box, the #content_box just goes blank.

Any help would be awesome!

EDIT ** changed #content_dov to #content_div - whoops

2
  • you should give parameter to success function like success: function(msg) { $("#content_dov").empty().html(msg); } Commented Jul 16, 2012 at 4:58
  • 1
    .load() is shorthand for an entirely new ajax request. It automatically overwrites the contents of it's target, so you don't need to call empty. Commented Jul 16, 2012 at 5:03

2 Answers 2

5

Why are you using two ajax requests? You just need to use

$("#content_dov").load("ajax/newcontent.php");

The full code is

function newContent()
{
    $("#content_dov").load("ajax/newcontent.php");
}
Sign up to request clarification or add additional context in comments.

Comments

3
function newContent()
{
  $.ajax({
      url: 'ajax/newcontent.php',
      success: function(data) 
      {
            $("#content_dov").html(data);
      }

      });
}

1 Comment

Both answers worked, but @Joyce Babu answer came first. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.