与cfhttp链接并在同一窗口中打开它

时间:2014-12-07 05:40:30

标签: jquery coldfusion

我正在运行cfhttp并将结果返回到jquery容器中..

现在cfhttp有一些我希望在容器内打开的链接。

它应该像点击链接一样 - 再次进行cfhtp调用并将结果放在同一个容器中

或者它应该像我的网址一样附加到链接的地址再次在我的容器中打开..

我不是在这里写任何代码,因为在这个时间点,我不知道该怎么做以及如何开始

请提出建议

以下是其中两个更新:

  1. 使用POST实际上,表单位于文件内容[<form id="qform" onsubmit="return Form1_Validator(this)" name="qform" action="http://mysearch.com/9.asp?type=299" method="post">]

  2. 另一个是类似:http://mysearch.com/9.asp?action=&companyQ=&type=299&pagenum=1

  3. 的链接

    更新#2

    现在我添加了这个

    <cfset lnk = cfhttp.filecontent>
    
    <cfset ldel = chr(7)>
    <cfset already_parsed = "">
    <cfset URLArray = REMatch("(http[s]?):\/\/[^\s\<"",]*",lnk) />
    <cfloop array="#URLArray#" index="url_i">
      <!--- Trim .,!,?  off the end of the url --->
      <cfset url_i = ReReplace(url_i,"(\?|\!|\.|,)$","")>
      <cfif not listfind(already_parsed,url_i,ldel)>
        <cfset already_parsed = listappend(already_parsed,url_i,ldel) />
        <cfoutput>Currently outputting #url_i#<br /></cfoutput>
        <CFSET lnk = replace(lnk, url_i, "originalpage.cfm?process=#Name#&u=" & url_i)>
      </cfif>
    </cfloop>
    <cfoutput>#trim(lnk)#</cfoutput>
    

    它显示了我的网址:Currently outputting http://mysearch.com/r=100&type=29

    它显示了我从URL获得的链接和数据。当我点击URL中的任何链接时,它什么都不做,你认为我们需要调用cfhttp来获取新内容并再次显示在同一个容器中。

    我认为我们需要这样的电话,我尝试修改为:

    <cfset ldel = chr(7)>
    <cfset already_parsed = "">
    <cfset URLArray = REMatch("(http[s]?):\/\/[^\s\<"",]*",lnk) />
    <cfloop array="#URLArray#" index="url_i">
      <!--- Trim .,!,?  off the end of the url --->
      <cfset url_i = ReReplace(url_i,"(\?|\!|\.|,)$","")>
      <cfif not listfind(already_parsed,url_i,ldel)>
        <cfset already_parsed = listappend(already_parsed,url_i,ldel) />
        <cfoutput>Currently outputting #url_i#<br /></cfoutput>
        <CFSET lnk = cfhttp.url(url_i)>
      </cfif>
    </cfloop>
    <cfoutput>#trim(lnk)#</cfoutput>
    

    上述工作,我试过,但它没有显示任何东西

1 个答案:

答案 0 :(得分:0)

这是一个简单的例子。我使用一个struct来创建一个伪cfhttp.filecontent进行测试。我使用一个非常简单和慷慨的url解析正则表达式,但如果这不适合你的需要,你可以在互联网上找到url regex。

<cfset cfhttp = structNew() />
<cfsavecontent variable="cfhttp.filecontent"><form id="qform" onsubmit="return Form1_Validator(this)" name="qform" action="http://mysearch.com/9.asp?type=299" method="post">Here is also a link to <a href="http://google.com">http://google.com</a>. This is the answer to the question http://stackoverflow.com/questions/27339981/linking-with-cfhttp-and-opening-it-in-same-window, but not the answer to the question http://stackoverflow.com/questions/27340137/test-if-externalptr-object-is-null. Again, the url is http://stackoverflow.com/questions/27339981/linking-with-cfhttp-and-opening-it-in-same-window</form></cfsavecontent>

<cfset URLArray = REMatch("(http[s]?):\/\/[^\s\<"",]*",cfhttp.filecontent) />
<cfset ResultsArray = ArrayNew(1)>
<cfloop array="#URLArray#" index="url_i">
  <!--- Trim .,!,?  off the end of the url --->
  <cfset url_i = ReReplace(url_i,"(\?|\!|\.|,)$","")>
    Do stuff with array element.
    <cfoutput>Currently outputting #url_i#<br /></cfoutput>
    <cfhttp url="#url_i#"... result="subObj">
      ...
    </cfhttp>
    <cfset ArrayAppend(ResultsArray,subObj)>
    <cfoutput>#subobj.filecontent#</cfoutput>
</cfloop>

现在,您可能会在文档中遇到两次相同的网址,并且您不想两次ping同一个网址,我想。你需要更像这样的代码。

<cfset cfhttp = structNew() />
<cfsavecontent variable="cfhttp.filecontent"><form id="qform" onsubmit="return Form1_Validator(this)" name="qform" action="http://mysearch.com/9.asp?type=299" method="post">Here is also a link to <a href="http://google.com">http://google.com</a>. This is the answer to the question http://stackoverflow.com/questions/27339981/linking-with-cfhttp-and-opening-it-in-same-window, but not the answer to the question http://stackoverflow.com/questions/27340137/test-if-externalptr-object-is-null. Again, the url is http://stackoverflow.com/questions/27339981/linking-with-cfhttp-and-opening-it-in-same-window</form></cfsavecontent>

<!--- Defining a very unique delimiter --->
<cfset ldel = chr(7)>
<cfset already_parsed = "">
<cfset URLArray = REMatch("(http[s]?):\/\/[^\s\<"",]*",cfhttp.filecontent) />
<cfset ResultsArray = ArrayNew(1)>
<cfloop array="#URLArray#" index="url_i">
  <!--- Trim .,!,?  off the end of the url --->
  <cfset url_i = ReReplace(url_i,"(\?|\!|\.|,)$","")>
  <cfif not listfind(already_parsed,url_i,ldel)>
    <cfset already_parsed = listappend(already_parsed,url_i,ldel) />
    <cfoutput>Currently outputting #url_i#<br /></cfoutput>
    <cfhttp url="#url_i#"... result="subObj">
      ...
    </cfhttp>
    <cfset ArrayAppend(ResultsArray,subObj)>
    <cfoutput>#subobj.filecontent#</cfoutput>
  </cfif>
</cfloop>