Saturday, January 26, 2013

Re: Moving variable names to external js file - how can I map the variables values to the new location?

Hi,

Thanks for your response.

A lot of the content is generated by javascript, including the elements which fire the javascript functions.  For example there is a method which writes a checkbox to the DOM - the value of which is given by an AJAX query. When it is checked/unchecked it fires a js function sending the value to the server (at some url given by a template variable). Because the checkbox is itself produced by a function within the external/static myjavascript.js file I experience the same problem attributing a data property as you suggest.

On Saturday, January 26, 2013 2:50:44 PM UTC, juanblo wrote:
Hi,

You can use data properties, for example:

# Template

<div id="my_container" data-url="{{ url_endpoints param }}">
</div>

# Javascript

$('#address').editable({
    type: 'text',
    url: $('#my_container').data('url'),
    ......
});

Hope this helps,

On Sat, Jan 26, 2013 at 8:54 AM, Jason <1jason....@gmail.com> wrote:
Hi there.

I am moving some javascript from my html to an external js file. At present however, whenever my pages are rendered I use variable names to give url endpoints, for example: 

    $('#address').editable(          {              type: 'text',              send : "always",              url: '{{ url_endpoints.logged_in_change_address }}', // the variable value becomes something like /au/change_address              title: 'Enter kindle address',              success: function() {                  window.location.reload();              }          }      );  

However, in moving the js to the external file, when rendering the html page the variable values are no longer mapped to the variable name within the external js file. The information is still there, I was just wondering if I could somehow pull in the variable values without declaring global variables or hardcoding the urls in the js?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Juan 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment