Note that there are some explanatory texts on larger screens.

plurals
  1. POCan you store an Ajax variable value from the previous request?
    primarykey
    data
    text
    <p>I have the following jQuery Ajax code, and it would seem (unless I've misunderstood the problem) that without defining the <code>page</code> variable within the <code>$("#imgNum").change(function(){});</code>, the ajax call following the function will not fire.</p> <p>Since the <code>page</code> variable is set based on when a button is clicked (which fire's its own ajax call), I'm wondering if there is a way of setting <code>page</code> to be equal to the last value it was set at? Unless there is another way of saving this value to call on it, and refreshing it every time a certain function is performed?</p> <p><strong>The jQuery:</strong></p> <pre><code>function loadData(page, value){ loading_show(); gallery_hide(); $.ajax ({ type: "GET", url: "new_arrivals_data.php", data: {page:page, imgs:value}, success: function(msg) { gallery_show(); $("#gallery_container").ajaxComplete(function(event, request, settings) { gallery_show(); $("#gallery_container").html(msg); }); }, error: function(jqXHR, textStatus, errorThrown) { // Tell the human that something broke. }, complete: function() { // This is always called regardless of success or failure. loading_hide(); } }); } loadData(1); // For first time page load default results $('#gallery_container .pagination li.active').live('click',function(){ var page = $(this).attr('p'); loadData(page); }); $('#go_btn').live('click',function(){ var page = parseInt($('.goto').val()); var no_of_pages = parseInt($('.total').attr('a')); if(page != 0 &amp;&amp; page &lt;= no_of_pages){ loadData(page); }else{ alert('Enter a PAGE between 1 and '+no_of_pages); $('.goto').val("").focus(); return false; } }); $("#imgNum").change(function(){ var sel = $(this); var value = sel.val(); //THIS IS WHERE I WANT TO DEFINE THE PAGE BASED ON IT'S MOST RECENT VALUE var page = ?; loadData(page, value); }) //You should store the current selected option in a cookie //For the sake of the example i'll set the default permanently to 12 var imgNum_selected = 16; //set the initial selected option and trigger the event $("#imgNum [value='"+imgNum_selected+"']").prop("selected","selected").change(); </code></pre> <p>Would this be possible to do by saving the current value in a cookie which is reserved whenever the value is changed? How do you store a value in a cookie, and then retrieve it?</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.
 

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