Monday 15 September 2014

jquery - I'm using the ajax .load method when but it only loads the content for a second then disappears -



jquery - I'm using the ajax .load method when but it only loads the content for a second then disappears -

i include jsfiddle ajax doesn't work in them

class="snippet-code-css lang-css prettyprint-override"> <script>// loads survay quesitons using ajax function sendajax() { $('#ajax').load('survey.html'); } </script> class="snippet-code-html lang-html prettyprint-override"><head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript" src="js/javascript.js"></script> <link rel=stylesheet href="css/code.css" type="text/css"> </head> <body> <form class="name" method="post"> name: <input type="text" name="name" /> <button id="load" onclick="sendajax()" class="button">next</button> <div id="ajax"> </div> </body> </html>

this code should loading

<div class= "section"> <img src="img/mbeef.png" alt="beef" class="choices" data-value="11"> <img src="img/mbacon.png" alt="bacon" class="choices" data-value="12"> <br> <button class="name" id="btn-show">submit</button>

a live example

it doesn't work when set script javascript.js file

edit

i changed code

// loads survay quesitons using ajax function sendajax(e) { e.preventdefault(); $('#ajax').load('survey.html'); } </script>

and im getting error uncaught typeerror: cannot read property 'preventdefault' of undefined

your page posting since button in form, seek using preventdefault

<button id="load" onclick="sendajax(event)" class="button">next</button> function sendajax(e) { e.preventdefault(); $('#ajax').load('survey.html'); }

jquery html ajax

No comments:

Post a Comment