Currently i use a fine working code for opening a modal with Jquery :
$(document).ready(function(){
$("span.ico-detail").click(function(){
modal.open({content: "View detail of " + $(this).parent().parent().attr("id")});
e.preventDefault();
});
});
And now the problem is : How can I use modal.open to open a HTML file named “view.html”, which contaning the string of “View detail of “?
What should I change the content : “xxx” with, so I can open the HTML file (view.html) and join it with other text ?
Thanks before.
If the
view.htmlis stored on a server and its content is static, then you can choose to preload the content of the file using ajax.I am creating a global variable
myAppNs. This will hold all app related variables. The idea is not pollute the global namespace with unnecessary variables. There are better and safer ways to create a namespace. If that interests you, you can google for the same.The ajax call preloads the content of the
view.htmland stores it inmyAppNs.viewContent. The click handler reads that content from the variable.There is a slight chance that the user can click the element before the ajax response is returned. If that’s an issue, you can always move the namespace creation and ajax call out of
document.readyand place it in theheadsection, immediately after referencingjquery. That ought to give the browser enough time to fetch the content before the dom is ready, but there is still that small possibility that the response might be delayed. If you need to ensure the user can click only if the data has been fetched, then bind the click handler inside thedonecallback of the ajax call.