混合使用 PHP 和 JavaScript 时显示值的最佳方法


best way to display values when mixing php and javascript

我有一个控制器.js它对php文件进行JSON调用。在 php 文件中,我需要看到一些值,当我回显它时它不会显示。

这是我的代码:

//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 
}

当我刷新页面时,顶部显示"否"???

将 JS 与 PHP 混合时显示值的最佳方法是什么?谢谢

更改:

echo $contentlocation;

自:

echo json_encode($contentlocation);

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