Reputation: 139
I am running the Code here as like this:
<script type="text/javascript" src="js/myjs.js?<cfoutput>#randnumber#</cfoutput>"></script>
<script type="text/javascript" src="own_id.cfm"></script>
<cfdump var="#own_id#">
It is throwing as error as:
Variable OWN_ID is undefined.
Now if i remove the
$(document).ready(function() {
$.ajax({
type: "POST",
url: 'set.cfm',
async: false,
data: 'own_id='+own_id,
success: function(i){
}
});
});
Error is throwing on own_id
. ReferenceError: own_id is not defined
own_id.cfm code:
<cfsetting showdebugoutput="no">
<cfset own_id = session.id_user>
<cfoutput>#own_id#</cfoutput>
Upvotes: 0
Views: 61
Reputation: 20804
This is a problem:
<script type="text/javascript" src="own_id.cfm"></script>
own_id.cfm is not a javascript file so that command is not going to do anything useful. Given the contents of that file, maybe you want this:
<cfinclude template="own_id.cfm">
That will solve your undefined variable problem in ColdFusion. For the jquery part, it might be a simple as surrounding the code block with cfoutput tags and changing this:
data: 'own_id='+own_id
to this:
data: 'own_id='+ #own_id#
But it's hard to say because the question does not say where that jquery code is.
Upvotes: 0
Reputation: 1220
In own_id.cfm, replace the code to this:
<cfsetting showdebugoutput="no">
<cfset own_id = session.id_user>
<cfoutput>var own_id = #own_id#;</cfoutput>
Otherwise, you are simply outputting the object's value to the page without supplying a variable assignment.
And it's not going to show up in your CF dump because you are calling the CFM template as a JS script file, therefore your CF variable will never be defined to get dumped.
Upvotes: 2