UPDATE: This is the CFC code that I'm using to retrieve the data.
I'm using the qTip jQuery plugin to create tooltips for a set of links.
Two problems:
How do I create a set of tooltips for three dynamically generated links where the content of the tooltip will also be dynamic:
a href="books.cfm?bookID=11">Book One
a href="books.cfm?bookID=22">Book Two
a href="books.cfm?bookID=33">Book Three
I would like to create a tooltip for each link. Each tooltip will then load details about each book. Thus I must pass the bookID to the tooltip:
$('#catalog a[href]').each(function()
{
$(this).qtip(
{
content: {
URL: 'cfcs/viewbooks.cfc?method=bookDetails',
data: { bookID: <cfoutput>#indexView.bookID#</cfoutput> },
method: 'get'
}
});
});
Unfortunately the above code is not working correctly.
I've gotten the followng to work when I've used a static 'bookID' instead of a dynamically generated number.
$("#catalog a[href]").qtip({
content: {
url: 'cfcs/viewbooks.cfc?=method=bookDetails',
data: { bookID: 11 },
method: 'get'
}
});
Even when it does work (by using a static number for 'bookID', I can't format the data correctly. It comes back as a query result, or a bunch of text strings. Should I send back the results as HTML? Unsure.
CFC:
<cffunction name="bookDetails" access="remote" returnType="any" returnformat="plain" output="true" hint="This grabs book details for the books.cfm page">
<cfargument name="bookID" type="numeric" required="true" hint="CFC will look for bookID and retrieve its details">
<cfset var bookDetails = "">
<!--- GET bookS FROM DATABASE --->
<cfquery name="bookDetails" datasource="">
SELECT
titles.titleName AS tName,
books.titleID,
books.releaseDate AS rDate,
genres.genreName AS gName,
books.bookID,
FROM
books
Inner Join titles ON titles.titleID = books.titleID
Inner Join genres ON genres.genreID = books.genreID
WHERE
(books.bookID = #ARGUMENTS.bookID#);
</cfquery>
<!--- RETURN VARIABLE --->
<cfreturn bookDetails>
</cffunction>
PS: I am an absolute NOVICE to Javascript and jQuery, so please try not to be as technical.
Many thanks!
i have also used qtip for my projects many time therefore I might be able to help you. As far as i understand your question that you need to fetch bookId from the url for e.g. for <a href="books.cfm?bookID=11"> you need to pass 11. For this you can use following code
$('#catalog a[href]').each(function()
{
var bi = parseInt($(this).attr("href").split("=")[1])
$(this).qtip(
{
content: {
url: 'cfcs/viewbooks.cfc?method=bookDetails',
data: { bookID: bi },
method: 'get'
},
api :{
onContentLoad : function(){ }
// view complete list at http://craigsworks.com/projects/qtip/docs/api/#callbacks
},
style: {
//for styling your qtip. http://craigsworks.com/projects/qtip/docs/tutorials/#styling. Also here you can provide nearly all css properties for main content wrapper.
}
});
});
Above code must send correct bookId to the server where you can fetch it from the get variable. For processing response you have two ways.
1) send html from the server that will be displayed as it is.
2) you can also generate html from the response at the client side using onContentLoad callback provided by the qtip But I recommend first way.
Why not use <cftooltip> instead of jQuery tooltip?
Related
I try to get an impression how to build a REST-API using FW/1 version 4.
I set this in my Application.cfc:
<cfset variables.framework.routes = [
{ "$GET/persons/:id/$" = "/persons/show/id/:id" }
]>
My controller method
<cffunction name="show">
<cfargument name="rc" type="struct" required="true">
<cfset local.strURL = variables.fw.buildURL(
action = 'persons.show',
queryString = 'id=123'
)>
<cfset variables.fw.renderData().data( { strURL = local.strURL } ).type( "json" )>
</cffunction>
I call /persons/123 and get this output:
{"URL":"/persons/show/id/123"}
I don't like the /show/ pathinfo in this generated URL. It's not part of the URL I requested in the browser (or via AJAX etc.). Is there a way to get rid of this in the generated URL?
This is not a functionality in FW/1. This was considered in 2012, but was rejected.
See: https://github.com/framework-one/fw1/issues/145
The core issue was (and is) according to Sean Corfield:
Interesting idea but I think you'll find that, in general, routes =>
URLs is actually a many-to-one mapping so you can't reliably go
backwards from URLs (actions / params) to a unique route. I've talked
that over a few times with people and so far no one has managed to
come up with a mapping that works in all cases.
I have inherited a external page where I have no control:
I have javascript sorting on that page: like http://www.exampledomain.com/javascript:void(1);
Now it has many links like this, the 1 you see is dynamic, what I want to is: convert this code to ColdFusion URL like http://www.exampledomain.com/sor=1&sort=asc & desc. The 1 should work as it is, like it should keep its value as it is 1,2,3,4 etc. I tried to do this with jQuery.
How can I alter these links in ColdFusion?
I tried to come up with some of Javascript solution but it did not work
$('#container').find('a').attr('href', function(i, old) {
var col = decodeURIComponent(old).match(/javascript:\s*sort\((.*?)\)/)[1];
return hrefcall+data+'&sortBy='+col;
Thanks
Your question is unclear, the source of the data is unknown and there are a few typoes.
This JQuery (1.9.1)
var ihref = "";
var col = 'somedata';
$("a").click(function (i) {
ihref = $(this).attr('href');
if (ihref.match(/javascript:\s*sort\(\d+\).*/i)) {
ihref = ihref.replace(/javascript:\s*sort\((\d+)\).*/i,"http://www.w3schools.com/sor=$1&sortBy=" + col);
$(this).attr('href',ihref);
alert("As a demonstration, you\'ll see the link is rewritten when a javascript:sort url is clicked.");
}
});
Will convert all javascript:void links as you wanted. I did change the dummy url to w3schools.com because the good folks who own w3 permit their site to be loaded in Iframes which is necessary to easily demonstrate that this code works.
Of course, JQuery only works when JS is enabled. Still, since you started with JQuery, I thought I might show you a working demonstration.
(The links don't actually work, because w3schools doesn't have pages at those points, but you can see in the status bar, the links are rewritten).
If you're retrieving the page via cfhttp.filecontent, you can do something like this
<cfset cfhttp.filecontent = ReReplaceNoCase(cfhttp.filecontent,"javascript:\s*sort\((\d+)\);?","http://www.w3schools.com/sor=\1&sort=asc","ALL")>
The ReReplaceNoCase() was tested against this sample code..
<cfset cfhttp = {} />
<cfset col = "somedata" />
<cfsavecontent variable="cfhttp.filecontent">
test - will not alter url<Br />
test - will alter url<Br />
test - will alter url<Br />
test - will not alter url<Br />
</cfsavecontent>
<cfset cfhttp.filecontent = ReReplaceNoCase(cfhttp.filecontent,"javascript:\s*sort\((\d+)\);?","http://www.w3schools.com/sor=\1&sortBy=#col#","ALL")>
<cfdump var="#cfhttp#">
I have 2 files: test.cfc and test.cfm. When I click the submit button in test.cfm, I am getting the following error:
"error: Object doesn't support this property of method".
I know it has something to do with the form reference inside the passForm function. But after googling for hours I am still unable to resolve the error. Any advice?
test.cfc
<cfcomponent>
<cffunction name="getForm" returntype="String" access="remote">
<cfargument name="theForm" type="struct">
</cffunction>
</cfcomponent>
test.cfm
<cfajaxproxy cfc="ajaxFunc.test" jsclassname="testCFC">
<script>
function passForm(theForm)
{
try
{
var e = new testCFC();
message = e.getForm(theForm);
ColdFusion.navigate('', 'myDiv');
}
}
</script>
Have you looked at the serializeJSON() and deserializeJSON() functions in ColdFusion?
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_s_03.html
Also, have a look at the following thread, which may be of help to you.
How to pass STRUCT - OR - JSON to Coldfusion CFC Method
Hope that helps.
Mikey.
I am new to sencha, and using sencha 2 mvc. I have a cfc returned json data, which I want to use in my list views. I have read about CFJsonReader and CFQueryReader, but both have been scripted for EXt Js 3 x. I cant see an mvc proper code for sencha 2 anywhere else. I tried many times and all in vain. Please some help suggest me/help me to solve my problem ...My output is like :
{"QUERY":{"COLUMNS":["CLIENTID"],"DATA":[[1013],[1010],[1016],[1017],[1013]]},"TOTALROWCOUNT":5}
Definition of store:
Ext.define('Mysample.store.clientsWithoutAgentOffers', {
extend: 'Ext.data.Store',
config: {
autoLoad: true,
model: 'BestHomePro.model.clientsModel',
proxy: {
type: 'ajax',
url: '/sample/b.cfc?method=getClients',
reader: cfReader
}
}
});
Please pls help me...
The proper format for JSON for Sencha Touch 2 is described here:
Sencha Docs - JSON Reader
I wrote this code to get the desired format of JSon:
<cfset retVal = ''>
<cfset qResult = ''>
<cfquery name="qResult">
<!--- any query here --->
</cfquery>
<cfset thisArrayBecomesJSON = [] />
<cfloop query="qResult">
<cfset thisArr = {
"text"= "#qResult.id#, #qResult.description#",
"value"= "#qResult.id#"
} />
<cfset arrayAppend( thisArrayBecomesJSON, thisArr ) />
</cfloop>
<cfoutput>#serializeJSON( thisArrayBecomesJSON )#</cfoutput>
Note: if you want to use this JSon for SelectField, it must have to have the 'text' and 'value' elemnts in it.
You can make up a function for this. The function should take an object and return its Sencha Supported JSon. If you make up a function, please share with others.
Thanks
I have a ColdFusion CFC function like this:
<cffunction access="remote" name="getResults"
returntype="struct"
returnformat="JSON"
output="no">
<cfargument name="q" required="true" type="array" />
...
</cffunction>
How do I call this function from jQuery? Neither form of array encoding by jQuery will get ColdFusion to see the value as array.
If you pass "q=a&q=b" (like with jQuery.ajaxSettings.traditional = true), the function will get the string "a,b", not an array. While splitting on comma may seem like a possibility, it will not work if one of the "q" values contains a comma. Also, ideally, the function on the server-side should not have to be aware of the problems of how to serialize the data over the wire, and should continue to take in an array.
If you pass "q[]=a&q[]=b" (the jQuery default), it will not map over to the "q" parameter. If you try to change the name of the "q" parameter to "q[]", the CFC will error out due to an invalid parameter name.
First thing to know is jQuery Ajax requests do not encode arrays so have you to use something else to encode the data (this is where jquery.JSON.js comes from referenced below). So with a the JSON encoded found there, I then figured out the correct syntax by working with cfajaxproxy and studying the URL it generates in Firebug:
http://localhost/remote.cfc?method=getResults&argumentCollection=%7B%22q%22%3A%5B1%2C2%5D%7D
Yes the "argumentcollection" approach is correct, and the variable "q" with a reference to an array is in there.
I used the following code as a test bed:
remote.cfc
<cfcomponent output="false">
<cffunction access="remote" name="getResults"
returntype="struct"
returnformat="JSON"
output="no">
<cfargument name="q" required="true" type="array" />
<cfreturn {a=1,b=2}>
</cffunction>
</cfcomponent>
remote.cfm to see how cfajaxproxy generates its url
<cfajaxproxy cfc="Remote" jsclassname="Remote">
<cfoutput>
<script language="javascript" type="text/javascript">
var oRemote = new Remote();
alert(oRemote.getResults([1,2]));
</script>
</cfoutput>
remote.html doing it with jQuery
<script language="javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script language="javascript" src="jquery.JSON.js"></script>
<script language="javascript" type="text/javascript">
var argumentCollection = { q: [1,2] };
$.ajax({
url: 'remote.cfc',
data: {
method: 'getResults',
argumentCollection: $.JSON.encode(argumentCollection)
},
success: function(response) {
alert(response);
},
dataType: 'json'
});
</script>
Investigating this problem, I found the following blog post:
http://www.coldfusionjedi.com/index.cfm/2010/3/23/Using-jQuery-to-post-an-array-to-a-ColdFusion-Component - This suggested encoding the array as a JSON string, and then deserializing it inside the CFC method, with the unfortunate impact of requiring the CFC function to have to change to deal with JSON.
So I investigated further, and here's the best solution I have found so far.
By looking at the HTTP calls made when using cfajaxproxy, I discovered that you can send a single argumentCollection parameter as a JSON string to call the remote CFC method.
So the client side call looks something like this (using jquery-json plugin to do the serialization):
var params = {q: ['a', '1,2,3']};
$.getJSON('My.cfc?method=getResults', {argumentCollection: $.toJSON(params)}, function(data) {
// handle data
});
How about checking your values for commas and escaping them before passing to Coldfusion, then use ListToArray to convert and (if necessary) re-encode the commas?