Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to submit field value with Ajax
    primarykey
    data
    text
    <p>I know that there was a similar questions to this, but I tried everything and nothing seems to work. I'm not that good with ajax thats why i posted this question. </p> <pre><code>$("#buttons_holder").find("#add_users").click(function() { var ob = document.getElementById('all_users[]'); var selected = new Array(); for (var i = 0; i &lt; ob.options.length; i++) { if (ob.options[i].selected) { selected.push(ob.options[i].value); }// if }// for var selected_users = selected; var link = $("#buttons_holder").find("#add_users").attr('href'); $.ajax({ url: link, type: 'POST', data: { s : selected_users }, 'success': function(data){ alert ('succes'); }, 'error' : function(data) { alert ('fail'); } }); }); </code></pre> <p>And I always get fail alerted. I try to alert all parametes(selected_users, link) before function and everything seems ok. Can anyone tell me what could be a problem? Thanks you all very much for your answers. </p> <p>EDIT: Here's my HTML Code:</p> <pre><code>&lt;div class="main_content"&gt; &lt;div id="users_holder"&gt; &lt;div class="div_grids"&gt; &lt;div class="inline_wrapper"&gt; &lt;h4&gt;Users that belong to selected company:&lt;/h4&gt; &lt;label for="company_users"&gt; &lt;select multiple="" name="company_users[]" id="company_users[]"&gt; &lt;option value="1"&gt;admin@sms.com&lt;/option&gt; &lt;option value="3"&gt;b@bba.com&lt;/option&gt; &lt;option value="5"&gt;dfsdf@dmfkdmf.com&lt;/option&gt; &lt;/select&gt; &lt;/label&gt; &lt;/div&gt; &lt;div style="margin-top:2%; margin-left:5%; margin-right:5%" id="buttons_holder" class="inline_wrapper"&gt; &lt;div class="common_add_button"&gt; &lt;a id="remove_users" name="remove_users" href="http://localhost/cake/crawler/companies/1/manage-agents/remove"&gt; &amp;gt;&amp;gt; &lt;/a&gt; &lt;/div&gt; &lt;div class="common_add_button"&gt; &lt;a id="add_users" name="add_users" href="http://localhost/cake/crawler/companies/1/manage-agents/add"&gt; &amp;lt;&amp;lt; &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="inline_wrapper"&gt; &lt;h4&gt;All users:&lt;/h4&gt; &lt;label for="all_users"&gt; &lt;select multiple="" name="all_users[]" id="all_users[]"&gt; &lt;option value="4"&gt;11111@qweqwe.com&lt;/option&gt; &lt;/select&gt; &lt;/label&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p></p> <p>SOLUTION: </p> <pre><code>$("#buttons_holder").find("#add_users").click(function() { var selected_users = $('#all_users option:selected').map(function() { return this.value }).get(); var link = '{$add_users_link}'; $.ajax({ url: link, type: 'POST', data: { 'new_users' : selected_users }, 'success': function(data) { App.Messages.showOkFlashMessage(data); }, 'error': function(data) { App.Messages.showErrorFlashMessage(data.responseText); } }); return false; }); </code></pre>
    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.
    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