Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this a valid jquery callback function call?
    primarykey
    data
    text
    <p>I executing a function like this,</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { getEntities("Clients/GetClients", 0, formatClientsResult); var maxvalues = $("#HfId").val(); $(".pager").pagination(maxvalues, { callback: getEntities("Clients/GetClients", formatClientsResult), current_page: 0, items_per_page: 5, num_display_entries: 5, next_text: 'Next', prev_text: 'Prev', num_edge_entries: 1 }); }); &lt;/script&gt; $(function() { $.ajaxSetup({ contentType: 'application/json; charset=utf-8', global: false, async: false, dataType: 'json', beforeSend: function() { $('.loading').show(); }, complete: function() { $('.loading').hide(); } }); }); function getEntities(url, currentPage, formatResultFunction) { $.ajax({ url: url, data: { 'currentPage': (currentPage + 1), 'pageSize': 5 }, success: function(data) { if (data.isRedirect &amp;&amp; data.isRedirect === true) { alert('must redirect to ' + data.redirectUrl); location = 'http://www.google.com'; } else { var divs = ''; $("#hfId").val(''); $("#ResultsDiv").empty(); $.each(data.Results, function() { divs += formatResultFunction(this); }); $("#ResultsDiv").append(divs); $(".resultsdiv:even").addClass("resultseven"); $(".resultsdiv").hover(function() { $(this).addClass("resultshover"); }, function() { $(this).removeClass("resultshover"); }); $("#HfId").val(""); $("#HfId").val(data.Count); } } }); return false; } function formatClientsResult(result) { return '&lt;div class="resultsdiv"&gt;&lt;br /&gt;&lt;span style="display: inline-block;width:220px;" class="resultName"&gt;' + result.ClientName + '&lt;/span&gt;&lt;span class="resultfields" style="padding-left:10px;"&gt;Mobile No&amp;nbsp;:&lt;/span&gt;&amp;nbsp;&lt;span class="resultfieldvalues"&gt;' + result.ClientMobNo + '&lt;/span&gt;&lt;span style="float:right; padding-right:2px;"&gt;&lt;input type="checkbox" value=' + result.ClientId + ' onclick="storeIds();"/&gt;&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;&lt;span class="resultfields"&gt;Address&amp;nbsp;:&lt;/span&gt;&amp;nbsp;&lt;span class="resultfieldvalues"&gt;' + result.ClientAddress + '&lt;/span&gt;&lt;/div&gt;'; } </code></pre> <p>and i inspected through firebug i found my request was,</p> <p><code>http://localhost:1115/0?currentPage=[object+HTMLDivElement]1&amp;pageSize=5</code>... Am i missing something...</p> <p>When executing on initial load the request is,</p> <p><code>http://localhost:1115/Clients/GetClients?currentPage=1&amp;pageSize=5</code></p> <p>This seems to work but Only the callback function fails...</p> <p>I am using this <a href="http://d-scribe.de/webtools/jquery-pagination/lib/jquery_pagination/README" rel="nofollow noreferrer">jquery pagination plugin</a></p> <p>As suggested by darin,</p> <pre><code>$(document).ready(function() { getEntities("Clients/GetClients", 0, formatClientsResult); var maxvalues = $("#HfId").val(); $(".pager").pagination(maxvalues, { callback: function() { getEntities("Clients/GetClients", 0, formatClientsResult); }, current_page: 0, items_per_page: 5, num_display_entries: 5, next_text: 'Next', prev_text: 'Prev', num_edge_entries: 1 }); </code></pre> <p>My controller action,</p> <pre><code> public JsonResult GetClients(int currentPage, int pageSize) { if (Session["userId"]!=null) { var clients = clirep.FindAllClients(Convert.ToInt32(Session["userId"])).AsQueryable(); var count = clients.Count(); var results = new PagedList&lt;ClientBO&gt;(clients, currentPage - 1, pageSize); var genericResult = new { Count = count, Results = results ,isRedirect=false}; return Json(genericResult); } else { var genericResult = new {redirectUrl = Url.Action("Create", "Registration"), isRedirect = true }; return Json(genericResult); } } </code></pre> <p>And my model,</p> <pre><code>public IQueryable&lt;ClientBO&gt; FindAllClients(int userId) { var client = from c in taxidb.Clients where c.CreatedBy == userId &amp;&amp; c.IsDeleted == 0 select new ClientBO() { ClientId = c.ClientId, ClientName= c.ClientName, ClientMobNo= Convert.ToString(c.ClientMobNo), ClientAddress= c.ClientAddress }; return client; } </code></pre> <p>and my view,</p> <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;TaxiMVC.Models.Client&gt;" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"&gt; Index &lt;/asp:Content&gt; &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt; &lt;h2&gt; Clients&lt;/h2&gt; &lt;input type="hidden" id="hfId" /&gt; &lt;input type="hidden" id="hfEditId" /&gt; &lt;div id="ErrorDiv"&gt; &lt;/div&gt; &lt;div id="ImageButtonDiv"&gt; &lt;input type="button" class="addbuttons" onclick="return showadd();" /&gt; &lt;input type="button" class="editbuttons" onclick="if(editdetails()){return getClientbyId($('#hfId').val());}" /&gt; &lt;input type="button" class="deletebuttons" onclick="if(deletedetails()){return deleteClients($('#hfId').val());}" /&gt; &lt;/div&gt; &lt;div id="ResultsDiv"&gt; &lt;/div&gt; &lt;div id="PagerDown" class="pager"&gt; &lt;/div&gt; &lt;div id="adddiv" style="display: none;"&gt; &lt;form id="addform" autocomplete="off" action=""&gt; &lt;fieldset&gt; &lt;legend&gt;Client Details&lt;/legend&gt; &lt;table cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tr&gt; &lt;td class="tdfields" style="width: 25%; padding-right: 20px;" align="right"&gt; Client Name&amp;nbsp;: &lt;/td&gt; &lt;td style="width: 20%;"&gt; &lt;%= Html.TextBox("Name", null, new { @class = "text_box_height_14_width_150" })%&gt; &amp;nbsp; &lt;/td&gt; &lt;td style="width: 55%;" class="status"&gt; &amp;nbsp; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="tdfields" style="width: 25%; padding-right: 20px;" align="right"&gt; Mobile No&amp;nbsp;: &lt;/td&gt; &lt;td style="width: 20%;"&gt; &lt;%= Html.TextBox("MobileNo", null, new { @class = "text_box_height_14_width_150" })%&gt; &amp;nbsp; &lt;/td&gt; &lt;td style="width: 55%;" class="status"&gt; &amp;nbsp; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="tdfields" style="width: 25%; padding-right: 20px;" align="right"&gt; Address&amp;nbsp;: &lt;/td&gt; &lt;td style="width: 20%;"&gt; &lt;%= Html.TextArea("Address", null, 6, 42, new { @class = "multiline_text_box_height_14_width_200" })%&gt; &amp;nbsp; &lt;/td&gt; &lt;td style="width: 55%;" class="status"&gt; &amp;nbsp; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2" align="center"&gt; &lt;div class="form-submit"&gt; &lt;input type="submit" value="Submit" id="submit" /&gt; &amp;nbsp;&amp;nbsp;&lt;input type="button" value="Cancel" id="cancel" onclick="return showResultsdiv();" /&gt; &lt;/div&gt; &lt;/td&gt; &lt;td&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;/div&gt; &lt;input id="HfId" type="hidden" /&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { // getClients(0); getEntities("Clients/GetClients", 0, formatClientsResult); var maxvalues = $("#HfId").val(); $(".pager").pagination(maxvalues, { callback: function() { getEntities("Clients/GetClients", 0, formatClientsResult); }, current_page: 0, items_per_page: 5, num_display_entries: 5, next_text: 'Next', prev_text: 'Prev', num_edge_entries: 1 }); var validator = $("#addform").validate({ rules: { Name: "required", MobileNo: { required: true, number: true, minlength: 10 }, Address: "required" }, messages: { Name: "please provide a client name", MobileNo: { required: "Please provide a mobile phone no", number: "Please provide a mobile phone no", rangelength: jQuery.format("Enter at least {0} characters") }, Address: "please provide client address" }, // the errorPlacement has to take the table layout into account errorPlacement: function(error, element) { error.appendTo(element.parent().next()); }, // set this class to error-labels to indicate valid fields success: function(label) { // set &amp;nbsp; as text for IE label.html("&amp;nbsp;").addClass("checked"); }, submitHandler: function(form) { if ($("#hfEditId").val() == "") { $.ajax({ url: "Clients/ClientCreate", data: { 'clientName': $("#Name").val(), 'clientMobNo': $("#MobileNo").val(), 'clientAddress': $("#Address").val() }, contentType: "application/json; charset=utf-8", global: false, async: false, dataType: "json", beforeSend: function() { $('.loading').show(); }, complete: function() { $('.loading').hide(); }, success: function(data) { if (data.Result == "Success") { $("#hfEditId").val(''); $("#addform").clearForm(); getEntities("Clients/GetClients", 0, formatClientsResult); $("#adddiv").hide(); $("#ResultsDiv").show(); $("#PagerDown").show(); $("#ImageButtonDiv").show(); var maxvalues = $("#HfId").val(); $(".pager").pagination(maxvalues, { callback: getEntities("Clients/ClientCreate", 0, formatClientsResult), current_page: 0, items_per_page: 5, num_display_entries: 5, next_text: 'Next', prev_text: 'Prev', num_edge_entries: 1 }); $("#alert").remove(); topBar('successfully added'); return false; } } }); } else { $.ajax({ url: "Clients/Clientupdate", data: { 'clientId': $("#hfEditId").val(), 'clientName': $("#Name").val(), 'clientMobNo': $("#MobileNo").val(), 'clientAddress': $("#Address").val() }, contentType: "application/json; charset=utf-8", global: false, async: false, dataType: "json", beforeSend: function() { $('.loading').show(); }, complete: function() { $('.loading').hide(); }, success: function(data) { if (data.Result == "Success") { $("#hfEditId").val(''); $("#addform").clearForm(); getEntities("Clients/GetClients", 0, formatClientsResult); $("#adddiv").hide(); $("#ResultsDiv").show(); $("#PagerDown").show(); $("#ImageButtonDiv").show(); var maxvalues = $("#HfId").val(); $(".pager").pagination(maxvalues, { callback: getEntities("Clients / Clientupdate", 0, formatClientsResult), current_page: 0, items_per_page: 5, num_display_entries: 5, next_text: 'Next', prev_text: 'Prev', num_edge_entries: 1 }); $("#alert").remove(); topBar('successfully updated'); return false; } } }); } } }); }); &lt;/script&gt; &lt;/asp:Content&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    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