ajax查询返回字符串,从CFC返回结果之前,对AJAX查询执行字符串函数
||
我的頁面的頂部\'A-Z \'中包含字母。當用戶單擊字母時,我將對CFC進行AJAX調用,該CFC將根據所選字母對縮略圖目錄進行查詢,并返回相應文件名的列表。
當列表返回到頁面上的函數時,我正在使用split()對文件名執行多項功能以提取某些信息。例如,文件名的格式如下:lastname_firstnameIMG_1234_RGB.jpg
我的目標是提取CFC中的姓氏,名字和號碼,以便我可以標記縮略圖圖像并創建指向\'real \'文件的鏈接以供下載,例如lastname_firstnameIMG_1234_CMYK.tif等。
最初,我建立了AJAX函數以使用split()處理返回的列表,但IE中出現錯誤。為了緩解此問題,我寧愿在CFC中執行字符串函數并返回準備就緒的數據。
返回數據結構之前,如何在CFC中執行字符串函數?
編輯此設置在Safari和FF中享有盛譽,但在IE中產生了錯誤。我嘗試修改split()函數,并取得了一些成功,但是,當然,它在FF中無法正常工作。同樣,我的目標是消除JavaScript字符串mod,并在CFC中進行操作。
這是我的CFC:
action=\"list\"
directory=\"#thumbsdir#\"
recurse=\"true\"
listinfo=\"name\"
name=\"qFile\"
filter=\"#local.data#\"
/>
和我的AJAX函數(包裝在document.ready函數中...):
$(\'.lastname\').click(function(e){
e.preventDefault();
$(\'#emptymessage\').hide();
$(\'#searching\').show();
$(\'#content\').html(\"\");
var alpha = $(this).attr(\'id\');
$.getJSON(\"cfcengine.cfc?method=List&returnformat=json&queryFormat=column\",
{letter:alpha},
function(res, code) {
var s = \"\";
if(res.message.ROWCOUNT > 0) {
$(\'#searching\').hide();
for(var i=0; i
//This is all the stuff I want to get rid of...
var theFile = res.message.DATA.Name[i]
var theLastName = theFile.split(/_(.+)/)[0];
var theRest = theFile.split(/_(.+)/)[1];
var theFirstNameAll = theRest.split(/_(.+)/)[0];
var theFirstName = theFirstNameAll.split(/(?:IMG)/)[0];
var theImageAll = theRest.split(/_(.+)/)[1];
var theImage = theImageAll.split(/_(.+)/)[0];
var bw = theLastName + \'_\' + theFirstName + \'IMG_\' + theImage + \'_BW.jpg\';
var rgb = theLastName + \'_\' + theFirstName + \'IMG_\' + theImage + \'_RGB.jpg\';
//Right now I\'m just returning the name to the page until debugging is complete...
s += \'
\' + res.message.DATA.Name[i] + \'\';
}
} else {
var s = \"Sorry, nothing matched your search.\";
}
$(\"#content\").html(s);
//End response
}
//End getJSON
);
//End plist click function
});
總結
以上是生活随笔為你收集整理的ajax查询返回字符串,从CFC返回结果之前,对AJAX查询执行字符串函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何用js获取外联css,内联外联CSS
- 下一篇: ajax静态页面实例,AJAX实例:Aj