Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery: Calling a function from AJAX request
    primarykey
    data
    text
    <p>I'm trying to call a function when I get success from my ajax call, but it's not working. This is what I've tryed so far.</p> <pre><code>function dtMRPReasonCode(dt) { var data = null; jQuery.ajax({ type: "POST", data: {}, url: "Index.aspx/getMRPReasonCodeReport", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { if (msg.d) { console.log(dt); console.log(msg.d); buildTableBody(dt, msg.d); } }, error: function(xhr, ajaxOptions, thrownError) { alert("Error: dtMRPReasonCode"); } }); return false; } function buildTableBody(dt, obj) { dt.fnClearTable(); data = []; $(obj).each(function(index, value) { element = []; element.push(value.Metric); element.push(value.Region); element.push(value.Plant); element.push(value.Customer); element.push(value.IMAC); element.push(value.NotFilled); element.push(value.Filled); element.push(value.Total); data.push(element); }); dt.fnAddData(data); } </code></pre> <p><img src="https://i.stack.imgur.com/Ip6PV.png" alt="enter image description here"> Thanks in advance!</p> <h1>Edit #1</h1> <p>I used <code>console.log</code> in order to show you what I got from <code>dt</code> and <code>msg.d</code> (Image)</p> <h1>Edit #2</h1> <p>If I paste the commands from <code>buildTableBody</code> function in the <code>success:</code> handler instead of calling <code>buildTableBody</code> function in the <code>success:</code> handler it actually works:</p> <pre><code>function dtMRPReasonCode(dt) { var data = null; jQuery.ajax({ type: "POST", data: {}, url: "Index.aspx/getMRPReasonCodeReport", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { dt.fnClearTable(); data = []; $(msg.d).each(function(index, value) { element = []; element.push(value.Metric); element.push(value.Region); element.push(value.Plant); element.push(value.Customer); element.push(value.IMAC); element.push(value.NotFilled); element.push(value.Filled); element.push(value.Total); data.push(element); }); dt.fnAddData(data); }, error: function(xhr, ajaxOptions, thrownError) { alert("Error: dtMRPReasonCode"); } }); return false; } </code></pre> <p>But it makes no sense to me, since this actually should work in both ways.</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