2011-04-22 45 views
0

$('#target').html(????????).ajax()在jQuery回调函数上运行PHP函数

需要此操作才能加载带有id目标的<div>中的php页面。我该如何调用这个php页面?

这是我的问题,这不是我的设置它试图包括JavaScript变量obj.info:

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

每当我尝试去解决它obj.info函数失败的变量。

+0

回调?这是什么框架? – colinmarc 2011-04-22 19:10:21

+3

你知道js正在运行客户端和php正在运行服务器端...? – Flinsch 2011-04-22 19:11:17

+6

更多详情+更多代码=更多答案。 – michelgotta 2011-04-22 19:20:28

回答

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

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

+0

谢谢,问题我有一个JS变量我需要传递给PHP脚本,我该怎么做? – John 2011-04-22 21:07:38

+0

你真的应该阅读我链接到的文档。但是,您可以将它传递给url:'url/to/php/script.php?myVar ='+ jsVar,或者您可以将它作为第二个参数作为映射传递:{myVar:jsVar} – Gregg 2011-04-22 21:27:10

0
$.ajax({ 
    'url/to/php/script.php', 
    data: { 'varName': yourJsVariable }, 
    success: function(response) { 
    // your php script returns HTML content 
    // 
    $('#element').html(response); 
    } 
}); 

检查阿贾克斯()页的详细信息:http://api.jquery.com/jQuery.ajax/