How to have success in .submit

Hi, can i ask if this is my form and i will use the .submit how do i returned message successfully or failed after submitting the form using .submit

 <form id="myform" action="tomyprocess.php">
    <input type="text" name="Fname">
   <input type="text" name="Mname">
  <input type="text" name="Lname">

is this correct ?



thank you in advance.

.submit doesn’t return any data, it just submits the form, and thus refreshes the page. It seems like you are looking to post your form with AJAX.

$('#myform').submit(function() {
    $.post($(this).attr('action'), $(this).serialize(), function(data) {
        if (data === 'successfull') {
        } else {
            alert('A problem occurred while submitting your data. Please try again later.');
    return false; // don't actually submit, let AJAX handle the posting

This assumes the page you post to only contains the word “successfull” and nothing else.

Your code should also be able to work without javascript, so for example, make sure you also validate at the server side, not just in javascript.

Hi ScallioXTX, Thank you for the reply, is that code will work if i have input type=“file” ?can i still get the value of uploaded file?

Thank you in advance.

No I don’t think it will function with file uploads, at least not in all browsers.
Is it just one file and nothing else? If so, you may want to look at an AJAX file uploader, like fine uploader

Thank you.,can i ask what if i will get the id of the file example

<input type="file" id="upload" name="upload">

Then the request

   // Then send via ajax
     var xx = $('#upload').val();

       type: 'post',
       data: {up:xx},
       url: 'to_process.php',


I can see now the value is posted but i am not sure if this the right way to have file upload.

please correct me if i am wrong

Thank you.

You get the name of the file but not the file itself. Please read my previous post again.