php - prepend html data in two section of page at once -
so i'll keep simple can bare me, i'm still learning.
i have ajax setup submit code create new category database , prepends page , shows without page refreshing. can pull exact same data on different areas of page @ once.
here stuck. goal finding way prepend 2 different data sets. 1 goes under new categories does, , pulls in field on create new post section of page. thought might element id or can't find on looking for.
so possible take prepend(html) , submit data differently 2 page areas @ once?
here code submission.
<script type="text/javascript" > $(function() { $(".update_button").click(function() { var boxval = $("#category").val(); var boxval = encodeuricomponent(boxval); var datastring1 = 'category='+ boxval; var dataconfirm = 'newfaqcategory=true'; var datastring = datastring1+'&'+dataconfirm; if(boxval=='') { alert("please enter title"); } else { $.ajax({ type: "post", url: "ajax/faqcn.php", data: datastring, cache: false, success: function(html){ $("ol#update").prepend(html); $("select#faqc_id").prepend(html); $("ol#update li:first").slidedown("slow"); document.getelementbyid('category').value=''; document.getelementbyid('category').focus(); } }); } return false; }); }); </script>
to implement @brett's suggestion, is, instead of sending html code ajax request, send json 2 pieces of html, you'd need this:
php ajax response:
$returnvalue = array(); $returnvalue["html1"] = "<b>html new categories</b>"; $returnvalue["html2"] = "<b>html new post section</b>"; exit(json_encode($returnvalue));
then in javascript you'd have:
$.ajax({ type: "post", url: "ajax/faqcn.php", data: datastring, datatype: "json", // type of data you're expecting server cache: false }) .done(function(data) { // put html received in right place $("#html1").prepend(data.html1); $("#html2").prepend(data.html2); });
one last note, "success" callback deprecated of jquery 1.8, it's recommended use .done()
instead.
Comments
Post a Comment