0

$('#target').html(????????) or .ajax() ?

Need this to load a php page in the <div> with id target. How do I call that php page?

This is my problem it wasn't my setup it was trying to include the javascript variable obj.info:

function(obj){jQuery.ajax({'url':'/controller/\'+obj.info+\'','cache':false,'success':function(html){jQuery('#target').html(html)}})}

Whenever I try to work the variable obj.info it the function fails.

4
  • callback? what framework is this? Commented Apr 22, 2011 at 19:10
  • 3
    You are aware that js is running client-side and php is running server-side...? Commented Apr 22, 2011 at 19:11
  • 6
    more details + more code = more answers. Commented Apr 22, 2011 at 19:20
  • you're gonna need a server request, probably ajax, if you this really had to be from PHP Commented Apr 22, 2011 at 19:35

2 Answers 2

1
$('#target').load('url/to/php/script.php');

http://api.jquery.com/load/

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

2 Comments

Thanks, question I have a js variable I need to pass to the php script, how would I do that?
You really should read the documentation that I linked to. But you can just pass it into the url: 'url/to/php/script.php?myVar=' + jsVar or you can pass it as a map as the second argument: {myVar:jsVar}
0
$.ajax({
  'url/to/php/script.php', 
  data: { 'varName': yourJsVariable },
  success: function(response) {
    // your php script returns HTML content
    //
    $('#element').html(response);
  }
});

Check the page on .ajax() for more info: http://api.jquery.com/jQuery.ajax/

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.