Send Html Form Post Data To File With Jquery?
I am trying to send post data to my post data file handler called postinfo.php with jQuery but so far I can make it. Here is my post.php code:
Edit: You also have a typo which may be preventing the browser from executing your JavaScript code at all:
<scripttype="text/javscript">
You're missing the second "a". This should be:
<scripttype="text/javascript">
Solution 2:
You MUST spell
text/javascript
correctlyYou need to assign the event handler on load
There should not be any need to return false as posted by some other people here
NEVER call anything submit in a form
Wrap your html in body tags
Use a correct DOCTYPE
For files you can have a look at uploadify or How can I upload files asynchronously?
Fixed code for point 1 to 6
<!DOCTYPE html><html><head><title>Test Ajax</title><scriptsrc="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script><scripttype="text/javascript">
$(function(){
$('#form_id').on('submit', function(e){
e.preventDefault();
$.ajax({
type: "POST",
url: "./postinfo.php",
data: $(this).serialize(),
success: function() {
alert('success');
}
});
});
});
</script></head><body><formmethod="post"id="form_id"><inputtype="text"name="ime"><inputtype="submit"value="Send"></form></body></html>
Post a Comment for "Send Html Form Post Data To File With Jquery?"