javascript - How to do a synchronous Jquery .load() -
i have webpage tabs inside it, , when click on tab should load text editor text file , put inside text editor.
however, text doesn't load synchronously, behaves asynchronously. though made should synchronous.
here's code :
function init(){ $( "#accordion" ).accordion({heightstyle: "content",collapsible: true}); $( "#tabs" ).tabs( { activate: function(click,ui) { ui.oldpanel.children("#editor").remove(); ui.newpanel.load("be.htm",function(response, status, xhr){ $("#editor").css("width","100%"); $("#editor").css("height","500px"); $.ajax( { url: "./load_content.php", async: false, data: "name="+ui.newtab.text(), success: loadcontent }); }); } } ); } function loadcontent(contenu){ alert(contenu); $("#textbox").html(contenu); }
as requested, tried make mcve
here be.htm , "editor" (i took out wasn't necessary)
<!doctype html> <html> <head> <title>rich text editor</title> </head> <body> <div id="textbox" contenteditable="true"><p>lorem ipsum</p></div> </body> </html>
here bv.html, webpage code must appear (the jquery script lcoally stored on computer you'll have input own paths, sorry
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>projet</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <!-- <link rel="stylesheet" href="yourpathhere/projet/jquery-ui.css">- --> <script src="yourpathhere/projet/jquery-2.1.3.js"></script> <script src="yourpathhere/projet/jquery-ui.js"></script> <script src="yourpathhere/projet/bv.js"></script> <script src="yourpathhere/projet/jstree.js"></script> <link rel="stylesheet" href="./bv.css"> <script> $(function() { init(); }); </script> </head> <body id="body"> <div id="tabs"> <ul> <li><a href="#tabs-1">onglet1</a></li> <li><a href="#tabs-2">onglet2</a></li> <li><a href="#tabs-3">onglet3</a></li> </ul> <div id="tabs-1"> </div> <div id="tabs-2"> </div> <div id="tabs-3"> </div> </div> </body> </html>
i gave full javascript code have far.
and here's php called ajax :
<?php $filename=$_get['name']; $data = file_get_contents("./".$filename); echo $data; return $data; ?>
and btw, i'm sorry if find code ugly, i'm starter told.
Comments
Post a Comment