Link to home
Start Free TrialLog in
Avatar of brihol44
brihol44

asked on

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

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

Avatar of dgrafx
dgrafx
Flag of United States of America image

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 ...
SOLUTION
Avatar of Coast Line
Coast Line
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brihol44
brihol44

ASKER

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!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awsome! Thx... that's exactly what I was looking for. Less spaghetti and more sauce.