[英]Including php file as JS
我正在嘗試將tiny_mce的image_list_url更改為php文件。
我將網址更改為image_list.php文件。 它生成與js文件相同的確切輸出文本。
但是即使給出相同的輸出,它也不會顯示圖像列表。
我想知道內容類型是否正在影響它?
我的JS文件內容:
// This list may be created by a server logic page PHP/ASP/ASPX/JSP in some backend system.
// There images will be displayed as a dropdown in all image dialogs if the "external_link_image_url"
// option is defined in TinyMCE init.
var tinyMCEImageList = new Array(
// Name, URL
["Logo 1", "media/logo.jpg"],
["Logo 2 Over", "media/logo_over.jpg"]
);
我的PHP代碼:
<?php
require('../../../system/config.php');
$strPath = APP_ROOT.DS.'sys_uploads/images/';
$objFileList = dir( $strPath );
$arrFileList = array();
while (false !== ($entry = $objFileList->read())) {
if( is_file( $strPath.$entry) )
$arrFileList[] = array($entry, ABS_URL.'/sys_uploads/images/'.$entry);
}
$objFileList->close();
header('Content-type: application/x-javascript');
//header('Content-type: text');
?>
// This list may be created by a server logic page PHP/ASP/ASPX/JSP in some backend system.
// There images will be displayed as a dropdown in all image dialogs if the "external_link_image_url"
// option is defined in TinyMCE init.
var tinyMCEImageList = new Array(
// Name, URL
<?php
if( count( $arrFileList )>0 )
foreach( $arrFileList as $dataRow ):
?>
["<?php echo $dataRow[0];?>", "<?php echo $dataRow[1];?>"],
<?php endforeach; ?>
);
我的PHP輸出:
// This list may be created by a server logic page PHP/ASP/ASPX/JSP in some backend system.
// There images will be displayed as a dropdown in all image dialogs if the "external_link_image_url"
// option is defined in TinyMCE init.
alert('test working or not');
var tinyMCEImageList = new Array(
// Name, URL
["Logo 1", "media/logo.jpg"],
["Logo 2 Over", "media/logo_over.jpg"]
);
編輯:
根據建議,我什至還添加了一條彈出消息,甚至沒有出現。
解:
鄧不知道我的代碼是什么錯誤,但從鏈接建議中找到了很好的解決方案:
http://tinymce.moxiecode.com/wiki.php/Configuration%3aexternal_image_list_url
無需更改任何標題。 只需輸出JavaScript。
js.php: alert("Working!")
test.htm: <script type="text/javascript" src="js.php"></script>
加載test.htm時,出現一個警告框
這絕對是標題類型不正確的問題。
你能換線嗎
header('Content-type:application / x-javascript');
至
header('Content-type:application / javascript');
由於application / x-javascript不是正確的javascript標頭。 告訴我這件事有沒有幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.