Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm building a page that displays my clients projects. In the database, each project record has a boolean flag indicating which category and class the projects belong to.

The projects categories; planning, landscape, environmental. And the classes; industrial, government, education, residential.

When the user wants to see "planning" projects for an "industrial" application, I query the database accordingly using URL parameters when the page loads:

SELECT project_id, name, location, description, planning, landscape
      , environment, industrial, government, education, residential 
FROM   projects 
WHERE  planning = 1 and 
       industrial = 1 

.. and display the first project in the result set on the page.

Here's where I need some help

Above the project display there are links to the other classes. Additionally, if other projects in the selected category/class exists there is a link that says "One of three - see the next project" if the query returns more projects in the planning category that are in the industrial class. I want to use an ajax function to load another project into the page when a user clicks any of the aforementioned links via .load() or .ajax(). How can I store the project ID's returned from the query by class so that I can access it later with the ajax call via the links on the page?

I'm familiar with the javascript/jQuery ajax part of the work - no problem there. I'm just not certain how to store the information on the page to access it.

share|improve this question
2  
You should provide more code sample. I'd love to help you. – Evik James Mar 16 '12 at 18:11
I think I need to delete this because I'm going to go a different direction. I don't think a fully javascript array is a well thought-out solution. I need to figure out how to create the arrays in my ColdFusion application or session scope and access them that way... – Ofeargall Mar 23 '12 at 20:12
Don't delete the question or answer or comments. Just explain why you chose to go a different route, if that's what you choose to do. – Evik James Mar 23 '12 at 20:34
1  
Got it. Sad thing is, now I need to ask a different question. I need to build this same array with just ColdFusion. I'll post that new question and see where it goes. Thanks Evik. – Ofeargall Mar 23 '12 at 20:56
I'll answer it in a little bit. – Evik James Mar 23 '12 at 21:33

1 Answer

It's hard telling exactly what data you need to pass without more code from you. I would suggesting outputting your links and using microdata like this:

<a data-project="#project_id#">#name#</a>

To access this, you just do this:

$("a").click(function(e) {
    e.preventDefault();
    var project_id = $(this).data("project");
    // You could load in your new data here
});
share|improve this answer
I'll get a code sample shortly. I think you've got me in the right track though.. – Ofeargall Mar 16 '12 at 18:47
You should use graceful degredation. If the user doesn't have Javascript enabled (or is using something like Noscript), you don't want your page to completely break. Just fill out the href to an actual page that displays the information, but add a click handler that overrides the click action to perform an Ajax load. – Josh Mar 20 '12 at 0:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.