0

i am running cfhttp and getting the results back in a jquery container..

Now that cfhttp has some links which i would like to ope inside the the container.

Either it should be like clicking on a link - make a cfhtp call again and bring the results in the same container

or it should be like appending with my url address to the linked address to open in my container again..

I am not writing any code here because at this point of time, i am not sure what to follow and how to start

please suggest something

Here is an Update two of them:

  1. using a POST Actually a form is inside the filecontent [<form id="qform" onsubmit="return Form1_Validator(this)" name="qform" action="http://mysearch.com/9.asp?type=299" method="post">]

  2. another is link like: http://mysearch.com/9.asp?action=&companyQ=&type=299&pagenum=1

Update #2

Now I added this

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

it shows me the url's like: Currently outputting http://mysearch.com/r=100&type=29

It shows the links and the data i get from the URL. When i click any link in the URL, it does nothing, do you think we need to call a cfhttp to fetch new contents and display in that same container again.

i think we need such call, i tried modifying as:

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

will the above work, i tried but it does not show up anything

  • You can use the ReMatch() function to extract urls out of `.filecontent`. This collects an array. You can then loop over the elements of the array and do whatever you want. – Regular Jo Dec 07 '14 at 06:03
  • can you some one example, i shall be very grateful to you –  Dec 07 '14 at 06:04
  • Provide a sample of what your cfhttp body looks like please, edit your question with the information. – Regular Jo Dec 07 '14 at 06:05
  • Updated my answer, it really should have most of what you need. You'll need to set specifics of the sub-cfhttp tag. It presents records to an array and outputs it, to show you that you can do either. – Regular Jo Dec 07 '14 at 18:46

1 Answers1

0

Here's a simple example. I use a struct to create a fake cfhttp.filecontent for testing. I use a very simple and generous url parsing regex, but you can find url regexes all over the internet if this doesn't suit your needs.

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

Now, it's likely you could encounter the same url twice in a document and you don't want to ping the same url twice, I'd think. You need code more like this.

<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>
Regular Jo
  • 5,190
  • 3
  • 25
  • 47
  • i made a change in original question, please check –  Dec 07 '14 at 07:38
  • i did the same way, it does not work, even i parsed th ciikie also so it should not go to login screnn, but it does nothing, just loads the page –  Dec 07 '14 at 18:48
  • Hi! Thanks for the Update: the coming page has the link like below as a pagination, i am trying the same code provided by you but it is loading a complete page `https://mysite.com/newdata.cfm?u=http://externalsite.com/9.asp?SessionFirst=&type=299&pagenum=2` –  Dec 08 '14 at 16:50