Solved

Just wanted to get some feedback on the methodology of how I use Coldfusion and (jQuery) $.ajaxy goodness..

Posted on 2014-03-08
5
219 Views
Last Modified: 2014-03-09
I'm curious if this is a standard way of doing this with Coldfusion + $.ajax. It seems that my code gets a little bloated from this way. And again my question is really just to explore other ways to not have full page refreshes.
<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>


<div class="loadData"></div>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

<script>
$(document).ready(function() {
	$(".loadData").load("mydata.cfm");
});

I might have other functions here that specifically work for a few unrelated items in the "loadData" content area.

</script>


</body>
</html>

#### mydata.cfm 

<!--- I usually create .cfc's for retrieving data but for simplicty I'm adding it here --->
<cfquery>
	SELECT *
	FROM TABLE
</cfquery>

<cfoutput>
#data# I could have functionality like deleting or updating to where I utilize jquery as well.
</cfoutput>

<script>
     I might have functions here that seem to only specifically work for this pages functionality here. Which makes sense (DOM) but I'm just exploring other ways to possibly handle the ajax awesomeness as I've mentioned above.
</script>

Open in new window

0
Comment
Question by:brihol44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 25

Expert Comment

by:dgrafx
ID: 39915703
are you asking if using $(".loadData").load("mydata.cfm"); to populate elements is ok - or is there a better way?

my opinion is that it is ok.

myself i might do the following instead though:

<div class="loadData"><cfinclude template="mydata.cfm"></div>
then to refresh it on some event i would reload it using using the $("#someelement").on('click', function() { $(".loadData").load("mydata.cfm"); } }); ...
(that's just for example)

OR if your question is different than that could you clarify please.

good luck ...
0
 
LVL 16

Assisted Solution

by:Gurpreet Singh Randhawa
Gurpreet Singh Randhawa earned 100 total points
ID: 39915754
The way @dgrafx told you and you working is the best method if you want to implement ajax with coldfusion.

If you want to explore other ways, use javascript mvs frameworks like AngularJS, KnockoutJS, Batman for writing same code in more MVC manner so you can get the relevant Output

Regards
0
 

Author Comment

by:brihol44
ID: 39915954
ok, thx. Just two questions: 1. Is it common to have specific javascript functions for say your "mydata.cfm" on that page? Seems like I have to add in some functions specifically used on that page at the bottom. Ideally it would be nice to just have one main scripts.js file for less clutter in the head or footer but I'm guessing the DOM of mydata.cfm loads differently so maybe that's just how it is.

<cfoutput> stuff...

<script>
 Do stuff...
</script>

2. Your method of the ".load" what advantage is that over the way I'm doing it? Just curious.

Thank you!
0
 
LVL 25

Accepted Solution

by:
dgrafx earned 400 total points
ID: 39915975
1. yes - create a master .js file - less clutter - stay organized
plus you do not want to add js functions in your mydata file - spaghetti code ya know ...
just like in CF you want to keep your functions in a cfc and all your cfcs in one location

2. using .on(...) will allow you to access dynamically written elements.
this may be a problem you've possibly encountered in the past ...
0
 

Author Closing Comment

by:brihol44
ID: 39916002
Awsome! Thx... that's exactly what I was looking for. Less spaghetti and more sauce.
0

Featured Post

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question