c# - MVC: Delay jquery script execution until after Layout script has completed -


i'm developing asp.net project uses quite bit of client side jquery scripting. in layout.cshtml page have ajax call returns information logged in user. pages in application depend on information. therefore need mechanism don't execute script in individual views until call on layout page has completed.

generally use jquery deferreds quite difficult calls in 2 unconnected files (e.g. layout.cshtml , individual view cshtml). other options can think of make initial call synchronous don't want or have sort of wait loop (e.g. settimeout(checkval, 200), neither solution appeals me.

below simplistic sample of trying do.

layout.cshtml

$(document).ready() {     function loaduserdata()     {         return $.ajax({                 type: "get",                 contenttype: "application/json",                 datatype: "json",                 url: baseurl + "/account/getusermeta",                 success: function (res) {                     $("#usermetadata").data('meta', res);                 }             });     } } 

sample view (index.cshtml)

$(document).ready() {     function dostuff()     {         //this may not available yet         var meta = $("#usermetadata").data('meta');     } } 


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -