1

I would like to learn how to achive the following with the other two functions, or at least the ajax function.

$('#myDiv').load('index.php #content');

How would I load #content in the index.php file, into #myDiv on the current page with the $.ajax and $.get methods?

The url param doesn't seem to take a selector with any other ajax method then load.

this doesn't work...

$.ajax({ 
  url: 'index.php #content', 
  success: function(data) { 
     $('#myDiv').html(data); 
  },
});

1 Answer 1

3

Remove #content from the URL and in the success function, try this:

$( '#myDiv' ).html( $( data ).filter( '#content' ).html() );

It would be nice if we could do it your way, but.... Maybe the jQuery team can implement this in the next release.

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

Comments

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.