Note that there are some explanatory texts on larger screens.

plurals
  1. POHow does AJAX handle multiples instances of a variable?
    primarykey
    data
    text
    <p>I am currently editing a WordPress plugin, which allows you to filter posts by category, once a category is selected, the posts for that caregory are displayed as a checklist on the widget, the user can select the posts they wish to display in their sidebar/widget area of the theme.</p> <p>I have taken the widget to the point that the user can select their post, the widget allows a single post to be selected, however if more than one is selected and the save button is pressed, the form returns only the last slected post.</p> <p>After some searching, I have found the problem to be on the form return. It is either to do with the update, or the way AJAX handles multiple instances of a variable.</p> <p>the information posted to the server is as follows:</p> <pre><code>action save-widget add_new id_base single_post_super_widget multi_number savewidgets 9bc3d79f1c sidebar lcp-sb widget-height 200 widget-id single_post_super_widget-2 widget-single_post_super_widget[2][object_to_use] 5005 widget-single_post_super_widget[2][object_to_use] 4892 widget-single_post_super_widget[2][object_to_use] 4607 widget-single_post_super_widget[2][object_type] 72 widget-single_post_super_widget[2][paged] 1 widget-single_post_super_widget[2][tab] all widget-single_post_super_widget[2][title_override] widget-width 400 widget_number 2 </code></pre> <p>Where <code>object_to_use</code> is the post(s) being selected.</p> <p>the information being sent is defined here:</p> <pre><code>var theArgs = { action: jQuery('input.widget_class:hidden', widgetDiv).first().val() + '-get-metabox', widget: widgetDivId, number: widgetNumber, blog_id: jQuery(widgetInputBase + 'blog_id').val(), object_type: jQuery(widgetInputBase + 'object_type').val(), tab: currentTab, paged: currentPage, object_to_use: jQuery('input[type=checkbox][name$="[object_to_use]['+currentTab+']"]:checked', widgetDiv).first().val(), title_override: jQuery(widgetInputBase + 'title_override').val(), excerpt_override: jQuery(widgetInputBase + 'excerpt_override').val(), searched: ('search' == currentTab) ? jQuery('input.quick-search', widgetDiv).first().val() : '' }; </code></pre> <p>and the jQuery.post action:</p> <pre><code>jQuery.post( ajaxurl, theArgs, function( r ) { jQuery('.ajax-feedback').css('visibility', 'hidden'); if ( r &amp;&amp; r.length &gt; 2 ) { jQuery('div.widget-content', widgetDiv).html(r); } } ); </code></pre> <p>In relation to the question, <code>widget-single_post_super_widget[2][object_to_use]</code> is being posted multiple times, how does AJAX handle this? Does each post/variable have to be unique?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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