Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ajax on submit no refresh form using php

ok so i know this ajax works, but i cant seem to understand why it's not submitting here.

<script type="text/javascript">
$(function(){
    $('input[type=submit]').click(function(){
        $.ajax({
            type: "POST",
            url: "postitem.php",
            data: $("#myform").serialize(),
            beforeSend: function(){
                $('#result').html('<img src="loading.gif" />');
            },
            success: function(data){
                $('#result').html(data);
            }
        });
    });
});

submit form

<form action="" method="post" onsubmit="return false;" id="myform">

submit button

<input type="hidden" value="Post" name="submit" /> 
<button type="submit" title="Done" style="height:33px; width:50px">
    <img src="../../css/images/plus_25.png" />
</button>

i'm pretty something is wrong with the button, but i want to keep the way the button is because alot of my other forms use this same button, thanks if you can explain to me why click this submit button does nothing.

like image 376
Outdated Computer Tech Avatar asked May 15 '26 22:05

Outdated Computer Tech


1 Answers

You are selecting an <input> instead of a <button>. I had success by changing your jQuery selector from this:

$('input[type=submit]')

to this:

$('button[type=submit]')

http://jsfiddle.net/H3Bcc/

like image 54
showdev Avatar answered May 17 '26 12:05

showdev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!