Note that there are some explanatory texts on larger screens.

plurals
  1. POWanting to load image and some text for the selected option in a dropdown list using Ajax
    primarykey
    data
    text
    <p>I can't find a decent example of this anywhere.</p> <p>Basically have a dropdown list, each option value is the <code>productID</code> and text is the Product name.</p> <p>I want to post all the selected option values to an action method that will return the respective images on document ready. Image data will the be passed to a function which will update the DOM and then execute the same function everytime a different option from dropdown list is selected to retrieve and change the selected options/product image only. </p> <p>The action method will return the image for this option/value to the client in an AJAX response, I also want to return the product description too.</p> <p>Should the response data-type be JSON or do I have to return it in some other way i.e HTTP response with image MIME type?</p> <p>Something like the below collects all the selected values in an array:</p> <pre><code>$(document).ready(function () { var arr = new Array(); $('select option').each(function () { arr.push($(this).val()); }); // This below will post it off: $.ajax({ type: "POST", url: "/System/GetProductImages", data: { arr: arr }, traditional: true, success: function (data) { mydata = data; OnSuccess(data) // &lt;--- The function that will load/update the images }, dataType: "json" //&lt;--- ? }); }); </code></pre> <p>I am not sure how to form the AJAX request correctly so I can request both an image and some text, or is it best to make separate calls when requiring different data types? Maybe I can pack them all in into an array of some sort? Also not to sure how the function that will update the DOM with the retrieved images will look.</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