Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4626218
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:23:12+00:00 2026-05-22T03:23:12+00:00

I have a page which uses jQuery for some AJAX-stuff und Django as main

  • 0

I have a page which uses jQuery for some AJAX-stuff und Django as main application server. Let’s say I have some link where I want to attach a ‘click’ handler, to display a jQuery Dialog where the content of the dialog is loaded via AJAX from the server. The server needs some kind of ID to generate the dialog content. This is is available in the original site-template and should pe passed to the server using JS. What would be the most correct (or “best practice”) way to store the mentioned ID in the page:

Methods

  1. Create a link and attache a “click” handler that does preventDefault() and use the href of the link in JS. I.e.: <a id="do-dialog" href="{% url app.views.some_view param=object.id %}">Show me!</a> and a JS that looks like this:

    $("#do-dialog").click(function (e) { 
       var url = $(this).attr("href");
       /* do ajax with url */
       e.preventDefault();
    });
    
  2. Encode the ID in a class or id attribute of the link. I.e: <a class="do-dialog object-{{ object.id }}" href="#">Show me!</a> and use some JS to get the ID from the class and use this.

  3. Violate HTML and put the ID in an custom attribute and fetch it from there: <a obj-id="{{ object.id }" class="do-dialog" href="#">Show me!</a>

Pros and Cons

  1. Looks like the most “valid” way to do this. The data is stored in a known attribute and can be used directly from JS. However, if the user has turned JS off, the user will be taken to a page that return JSON or XML. (Note: for this particular site it is totally okay to not work with JS is turned off!)

  2. Doesn’t have this disatvantage. With JS turned off, nothing will happen. However, you have to parse the id from the class-attribute, which looks a little bit ugly and error prone to me.

  3. Is no valid HTML. On the other hand you have the needed data directly available.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:23:13+00:00Added an answer on May 22, 2026 at 3:23 am

    Approach number 1 makes the most sense. You are actually embedding the data where its going to be used and its valid HTML. You could also put the data in a hidden element of a form. Or if you are using HTML5 you could use the new data- attributes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page, which uses jQuery Autocomplete on the second two textboxes (investigator
I have a system that uses a meta refresh to a logout page, which
I have a page which dynamically loads a section of content via AJAX. I'm
I'm delving into some AJAX and I'm trying to utilise jQuery. I have an
I'm designing a template creation tool, which uses a jQuery Ajax request that posts
I have an ASP.Net web page, which uses a Master Page template. The page
I have this jQuery code, which uses the toggle() function on a checkbox input
I have a page which spawns a popup browser window. I have a JavaScript
I have a page which does quite a bit of work and I don't
I have a page which is largely created by DOM script, which generates a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.