Sunday 15 January 2012

javascript - ajax append multiple times to same div -



javascript - ajax append multiple times to same div -

assuming have partial view editor box inputting info (asp.net application)

@html.editor("new", new { htmlattributes = new { @class = "my_editor" } })

in main view, have section i'd update partial view mentioned above using ajax call.

<div id="editor_section"></div>

my question is, possible continuously append same div using same partial view. in other words, phone call ajax once, , new input box appears. click on ajax link again, , sec input box appears coming same partial view obviously. , should able go on doing many times each time appending new input box under others.

yes possible, not efficient. should have create ajax phone call once, can cache html partial view in javascript variable, when append later, don't have create round trip server retrieve html have requested.

something like:

var inputhtml = null; var appendinput = function () { if (!inputhtml) { $.get('/input', function (data) { inputhtml = data; $('#somediv').append(inputhtml); }); } else { $('#somediv').append(inputhtml); } };

javascript jquery html ajax asp.net-mvc

No comments:

Post a Comment