Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Submitting Values Without Refresh

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #158712
    Junni
    Participant

    am trying to submit form without refreshing page, but it is not working.

    $(function () {
    $(‘#myForm’).on(‘submit’, function(e) {
    $.ajax({
    type: ‘post’,
    url: ‘bankwire.php’,
    data: $(‘form’).serialize(),
    success: function () {
    alert(‘MUST ALERT TO DETERMINE SUCCESS PAGE’);
    }
    });
    e.preventDefault();
    });
    });

    and the PHP code is of Bankwire.php

    include(“connect.php”);

    include(‘functions.php’);

    if(isset($_POST[‘submit’])){

    $amount = $_POST['amount'];
    $bankname = $_POST['bankn'];
    $acctitle = $_POST['acctitle'];
    $accno = $_POST['accno'];
    $branch = $_POST['branch'];
    $transid = $_POST['tid'];
    $curntc = $_POST['ccur'];
    $coment = $_POST['coment'];
    
    
    
    $bankwire = "INSERT INTO bankwire VALUES('$amount','$bankname','$acctitle','$accno','$branch','$transid','$curntc','$coment','$idon')";
    
    mysql_query($bankwire) or die(mysql_error());
    

    }

    #158722
    CrocoDillon
    Participant

    Make sure the quotes you use in JavaScript are straight quotes (' or "), it looks like yours are not though it could be copy pasting here that messes things up.

    You’re using a different selector for the form for the submit event handler and the serialize function. I think you can use $(this).serialize() to make sure you serialize the right data.

    Also take a look at jQuery’s $.post function. Though not needed, it’s a nice ajax wrapper for POST requests.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.