2013-10-25 97 views
0

我有一个controller.js,它可以对php文件进行JSON调用。在PHP文件中,我需要看到一些值,当我回显它时,它不显示。混合php和javascript时显示值的最佳方式

这里我的代码:

//Controller.js 
show: function(data) { 
var self = this, 
salesquoteguid = data && data.salesquoteguid || self.salesquoteguid; 

$.getJSON('data/load.salesquote.php', {salesquoteguid: salesquoteguid}, function(data) { 
self.set('salesquoteguid', salesquoteguid); 
self.set('content', data); 
self.set('pricemethod', data.pricemethod); 
self.set('salesquoteitems', data.salesquoteitems); 
    }); 
}, 

//data/load.salesquote.php 
function getSalesquoteitemRecords(//some parameter) 
{ 
    if ($contentlocation = App::getContentLocation()) { 
    $contentlocation.= 'images/item/'; 
$targetDirExists = PATH_CLEVVA.$contentlocation; 
$targetDir = PATH_CLEVVA_DISPLAY.$contentlocation; 
} 
    echo $contentlocation; // I need to see this value 
} 

当我刷新我的网页,我收到了“NO”显示在顶部???

当您将js与php混合使用时,显示值的最佳方式是什么? 感谢

回答

2

变化:

echo $contentlocation; 

到:

echo json_encode($contentlocation); 

因为$.getJSON需要脚本发送JSON。

+0

我在PHP部分有回声,并将其改为您的建议,但我的页面上仍然没有任何内容,除了“NO” –

+0

我没有在您的代码中看到显示“NO”的任何内容,所以我不知道在哪里这是来自。 – Barmar

+0

其实,我没有看到你的代码显示从服务器返回的数据。那是'self.set('content',data)'做的吗? – Barmar