简体   繁体   English

使用Coldfusion将特定的url插入javascript函数

[英]inserting a specific url to the javascript function using coldfusion

Here I am trying to do a kind of weird thing, Am not sure what goes best here but here it is: 在这里,我正在尝试做一种奇怪的事情,不确定在哪儿最好,但是在这里:

I have external page which is coming through from cfhttp. 我有来自cfhttp的外部页面。 in that page, i have a soring function and that sorting function calls itself with appending the actual url with it, so it is breaking: 在该页面中,我有一个排序函数,而排序函数通过在其后面附加实际网址来调用自身,因此它很糟糕:

what i am trying is to find out that URL fom the page itself and append it with the url value, i am not sure at this point, will i be able to do it or not, but i am trying and i need your help guys 我正在尝试的是找出页面本身的URL并在URL后面附加URL值,我现在不确定是否可以这样做,但是我正在尝试,我需要您的帮助

Here is the code i am trying: 这是我正在尝试的代码:

<cfset case1 = find('thisUrl',cfhttp.filecontent)>
    <cfdump var="#case1#">
    <cfif case1 NEQ 0>
        <cfset regeneratelink = insert('<cfoutput>#address#</cfoutput>','thisUrl',case1)>
    </cfif> 

For tis, I am getting an Error: 对于tis,我得到一个错误:

The third parameter (AtPosition) of the function Insert(SubString, InString, AtPosition), which is now equal to 13048, must be less than or equal to the length of the second parameter (String), which is now equal to thisUrl and has a length of 7

if the above what i am doing in coldfusion can be done in jquery, i am open for it, just want to make external sorting functionality work... 如果以上我在ColdFusion中所做的事情可以在jquery中完成,我愿意接受,只是想使外部排序功能起作用...

Your code as written tries to insert into #Address# based on the a position found in the string cfhttp.filecontent. 您编写的代码会尝试根据字符串cfhttp.filecontent中的位置将其插入#Address# The 2 strings are (apparently) not the same - so a URL found in one would not be positionally relevant to the other. 这两个字符串(显然)是不同的-因此,在一个字符串中找到的URL在位置上与另一个字符串无关。

What you may be trying to do is modify the resultant contents of the HTML retrieved by the cfhttp call and replace thisurl with #address# . 您可能要尝试做的是修改thisurl调用检索到的HTML的结果内容,并将此thisurl替换为#address# If that is the case you can simply replace it directly like so: 如果是这种情况,您可以直接将其替换为:

<cfset newHTML = replaceNocase(cfhttp.filecontent,'thisURL',Address)/>

Note - you don't need the quotes and pound signs inside the function. 注意-函数中不需要引号和井号。 Keep it clean. 保持干净。

Meanwhile, I'm not sure I'm clear on the end game here. 同时,我不确定我是否清楚这里的最终比赛。 The Javascript in the returned HTML will obviously not run on the server right? 返回的HTML中的Javascript显然不会在服务器上运行,对吗? Why are you altering it again? 为什么要再次更改它? Are you outputing the results to a page for a user? 您是否将结果输出到用户页面?

(I'm assuming in all of this that 'thisurl' is an actual url and you just gave us sampledata of 'thisurl')> (我假设所有这一切都是'thisurl'是实际的URL,而您只是给了我们'thisurl'的样本数据)>

Okay first, you can't use tags inside strings so this 好的,首先,您不能在字符串中使用标签

<cfset regeneratelink = insert('<cfoutput>#address#</cfoutput>','thisUrl',case1)>

should be this 应该是这个

<cfset regeneratelink = insert('#address#','thisUrl',case1)>

But even can be this 但是甚至可以是

<cfset regeneratelink = insert(address,'thisUrl',case1)>

Straight from wiki docs, the format to use the Insert function is this 直接来自Wiki文档,使用插入功能的格式是这样

Insert(substring, string, position)

So, when you search cfhttp.filecontent for thisURL, you're finding it at position 13,048. 因此,当您在cfhttp.filecontent中搜索thisURL时,会在位置13,048处找到它。

You're then trying to insert the address into the string thisURL as position 13,048 and it only has a length of 7. 然后,您尝试将地址插入字符串thisURL的位置13048,并且长度只有7。

So it seems like you actually want to use.. 所以看来您实际上想使用..

<cfset regeneratelink = insert(address, cfhttp.filecontent, case1)>

But that will will actually insert the substring into the string at the first character where 但这实际上会将子字符串插入到第一个字符处的字符串中,

<cfset regeneratelink = insert(address, cfhttp.filecontent, case1+len('thisurl'))>

However, if you're doing all that you can just use replace 但是,如果您正在做所有事情,则可以使用replace

<cfif find('thisUrl',cfhttp.filecontent)>
  <cfset regeneratelink = Replace(cfhttp.filecontent,'thisUrl','thisurl' & address,"ONE")>
<cfelse>
  <!--- 'thisURL' was not found, do something else? --->
</cfif>

Which replaces just the first occurrence. 它将仅替换第一次出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM