Question

After trying for about an hour without success... (coldfusion8) a dummy question, but I*m stuck:

My URL (Jquery Mobile, no pushstate, that's why it looks like it is):

 http://www.page.de/test/mem/search.cfm#/test/mem/search.cfm?id=9900000003869

If I output:

<cfdump output="e:\website\dump.txt" label="catch" var="#url#">

I get this:

catch - struct

ID: 9900000003869

But how do i access it... I'm trying forever, nothing works:

<cfdump output="e:\website\dump.txt" label="catch" var="#id#">
<cfdump output="e:\website\dump.txt" label="catch" var="#ID#">
<cfdump output="e:\website\dump.txt" label="catch" var="#url.id#">
<cfdump output="e:\website\dump.txt" label="catch" var="#url.ID#">
<cfdump output="e:\website\dump.txt" label="catch" var="#StructGetValue(url,"id")d#">
...

Thanks for helping!

Was it helpful?

Solution

Ok... This works:

  URL = http://www.page.de/test/mem/search.cfm#/test/mem/search.cfm?id=9900000003869

  <cfset objRequest = GetPageContext().GetRequest() />
  <cfset strUrl = right( objRequest.GetRequestUrl().Append( "?" & objRequest.GetQueryString() ).ToString(), 13)>

Credit

If someone finds an easier, please post. I will check as answer.

OTHER TIPS

Doing some research on fragment identifiers (which is a new term to me :( )prompted by Peter and Duncan's comments, I've found from wiki: http://en.wikipedia.org/wiki/Fragment_identifier

The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the server — of course the server typically helps to determine the MIME type, and the MIME type determines the processing of fragments. When an agent (such as a Web browser) requests a resource from a Web server, the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent processes the resource according to the document type and fragment value.

now, being your client IS sending the fragment and the url variable is accessible to you for some reason, using it is done by my original post to follow.

<cfoutput> 

is generally how you output a variable or other evaluations to the screen.

<cfset myName = "Travis">
<cfoutput>Hello, my name is #myName#</cfoutput>

You can also access the variable by using it in a statement that doesn't output anywhere.

<cfset myFullName = myName & " Mak">

You can also use the variables in a query

<cfquery name = "qSomeQuery" datasource = "#application.dsn#">
  select * from table where id = #url.id#
</cfquery>

However, that's the bad way to use it in a query, you should always use cfquery param.

<cfquery name = "qSomeQuery" datasource = "#application.dsn#">
  select * from table where id = <cfqueryparam cfsqltype="cf_sql_integer" value="#url.id#">
</cfquery>

The problem you're having in testing the variable is due to incorrect syntax.

<cfif isDefined("url.id")> verses <cfif isDefined(url.id)> a more accurate test is <cfif structKeyExists(url, "id")>

For some reason my CF server truncates everything in the url after the # but yours doesn't seem to have this problem. As your cfdump states, you can see your url variables so "accessing" the url variable is as easy as using it: #url.id# or testing it <cfif isDefined("url.id")>

You're trying to read this from a txt file?

Can you not simply use:

<cfdump label="catch" var="#url.id#" />

Does that work?

EDIT:

Could you try capturing and formatting what you need first then after, writing it to the file?

For example, try using:

<cfsavecontent variable="myFileContents">
<cfoutput>#url.id#</cfoutput>
</cfsavecontent>

<cffile action="Write" file="e:\website\dump.txt" output="#myFileContents#" />

I have not tested this code, but give it a go and see!

Might want to put a check on that URL variable too using isDefined()

Good luck.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top