Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to pass a variable to jquery when it starts or every action?
    primarykey
    data
    text
    <p>I'm super new to jquery and just stractching the surface of its awesomeness so sorry if this is a really basic question but I have a button on my site that once clicked posts some data to my server and I'm wondering how to provide jquery with data I want to be posted. I have made jquery refreshless forms but they have required the user to enter something which I post but now I want to send some data that is not entered or available on the webpage.</p> <p>On my site, I have a button to click on if you want to 'follow' a topic. If you follow a topic I need to send a topic_id and your user id to my server to start the process but I think putting this on my web page for jquery to capture would be confusing to users(if I can't pass variables I plan to do this approach but hide the fields). The userid/topicid is avaiable to my template engine but I'm unsure how to pass the data over to the script.</p> <p>Here's a example of my script html:</p> <pre><code>&lt;input type='button' value='Follow' id='btnFollow'&gt; </code></pre> <p>follow.js:</p> <pre><code>$(document).ready(function () { $('#btnFollow').click(function() { //$("#btnFollow").prop('value', 'Following'); if ($(this).val() == 'Follow') { $("#btnFollow").prop('value', 'Following') } else if ($(this).val() == 'Following') { $("#btnFollow").prop('value', 'Follow') $.ajax({ type: 'POST', url: '/follow_modification', async: true, data: { fe1: "test" }, complete: function(xmlRequestObject, successString){ ymmReceiveAjaxResponse(xmlRequestObject, successString); } }); } }) }); </code></pre> <p>How do I get info into the function from the html? So far all my javascripts have been triggered by clicks and then take data from the page.. if I have a variable in my template called {{ user_id }} how can I pass that to the script so when a click triggers a action then it'll have the data it needs to post?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload