I’m just learning how to use jquery, and I’m beyond confused. Here’s what I’m trying to do (for practice/learning purposes):
- Take an input
- Post the input into a div tag using jquery
Here’s my code.. but it’s not working
<script type="text/javascript">
function test(data) {
$.post("<?php echo $_SERVER['PHP_SELF']; ?>", function(data) {
$("#lol").innerHTML = data;
});
}
</script>
<form action="" onsubmit="test($(this.children()))" method="POST">
<input type="hidden"
value="derp" />
<input type="text"
name="herp" />
<a href="javascript:void(0)"
onclick="test($(this).parent())">
Submit
</a>
</form>
<div id="lol">...</div>
Some help/tutorial explanation would be absolutely wonderful. Thanks!
The
datavariable is being misused. If you want to send data with your post request, which you do, you’ll want something like this:In your example, the form data isn’t being sent at all. Hope this helps!
jQuery $.post() reference:
http://api.jquery.com/jQuery.post/