Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery select2 with remote data and asp.net
    primarykey
    data
    text
    <p>I am using select2 library for replacing select boxes. I rearranged example 7 that you can find on <a href="http://ivaynberg.github.com/select2/" rel="nofollow">Select2 library</a> page (scroll down with id <code>$("#e7").select2</code> etc...). I made my own generic handler that return serialized json data:</p> <p>GetData.asxh view : public class GetData : IHttpHandler { public bool IsReusable { get { return false; } }</p> <pre><code> public class RecipesList { public int total { get; set; } public List&lt;TopRecipeTable&gt; recipes { get; set; } public RecipesList() { } public RecipesList(int total, List&lt;TopRecipeTable&gt; recipes) { this.total = total; this.recipes = recipes; } } private string GenerateJsonSerializedObject(int languageId, string orderBy) { RecipesList recipeList = new RecipesList(15, DBDataBase.GetTopRecipesByNumberOfRecipes(languageId, 15)); return new JavaScriptSerializer().Serialize(recipeList); } public void ProcessRequest(HttpContext context) { int languageId; bool languageParsed = int.TryParse(context.Request["languageId"], out languageId); string orderBy = (string)context.Request["orderBy"]; if (languageParsed &amp;&amp; orderBy != string.Empty) {enter code here context.Response.ContentType = "application/json"; var jsonValue = GenerateJsonSerializedObject(languageId, orderBy); context.Response.Write(jsonValue); } } </code></pre> <p>This generic handler returns the right format of json (I checked it with <a href="http://jsonformatter.curiousconcept.com/" rel="nofollow">this URL</a> ). My result (json) is also the same as the one in example on above mentioned page. But after this jquery doesn`t fire anymore.</p> <p>My script : </p> <pre><code>$(document).ready(function () { $("#e8").select2({ placeholder: "Search for a recipe", //minimumInputLength: 1, ajax: { url: "/Handlers/GetData.ashx", dataType: 'jsonp', data: function (term, page) { return { languageId: 1, orderBy: "TA" }; }, results: function (data, page) { alert(data.total); var more = (page * 10) &lt; data.total; // whether or not there are more results available // notice we return the value of more so Select2 knows if more results can be loaded return { results: data.recipes, more: more }; } }, formatResult: movieFormatResult, // omitted for brevity, see the source of this page formatSelection: movieFormatSelection, // omitted for brevity, see the source of this page dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results }); }); </code></pre> <p>I tried to write the same <code>alert(data.total)</code> in the original example and it worked but not in my version. So I have the right json format, the jquery calls my generic handler and also recieved parameters languageId ... and also return the right json format but than nothing. I don't know if I am missing something here, because I am sure that this thing could also work with a generic handler as well. I hope I gave enough information about my problem.</p> <pre><code>I can also add my result in jquery .ajax error handler : xhr.status = 200 ajaxOptions = parsererror horwnError = SyntaxError : invalid label If this is any helpful information </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.
    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