why is my form not submiting using ajax

Jordanbaggs

bit of a selfish question but I am really strugerling with ajax in general so I need some help. So basically Im trying to update and sql database using an 'onblur' function. heres my code:

code on index.php

   function saveStatus(){
var status =document.getElementById("statusForm").value;
$.ajax({
                url: 'saveStatus.php',
                type: 'post',
                data: 'feed_id=' + status,
                success: function(result){
                }
              }    
    <form id="statusUpdate" action = "whosout.php" method="post"> 
        <input type="text" id="statusForm" onblur="saveStatus()" 
        placeholder="<?php if($status!=null){ echo '&lsquo;'.$status.'&rsquo;';}
        else { echo 'Enter your status here.';}?>"> 
        </form>

and code on saveStatus.php

    <?
     require 'core.php';
     require 'connect.php';

      $status = $_POST['feed_id'];
      $idPerson = $_SESSION['user_id'];
      $query = "UPDATE person SET status = '".mysql_real_escape_string($status)."' 
     WHERE idPerson = '$idPerson'"; 
    $query_run = mysql_query($query);
     ?>

at the moment the sql database does not update when i click of the input box. Any help would be great!!

Sharikov Vladislav

Answer:

  1. You have to devide scripts and html output
  2. You forget );.You have to close $.ajax block.
  3. You miss } closing function saveStatus().

Code:

<script>
function saveStatus(){
    var status =document.getElementById("statusForm").value;
    $.ajax({
        url: 'saveStatus.php',
        type: 'post',
        data: 'feed_id=' + status,
        success: function(result){

        }
    }); // <-- Also, you forget `);` here 
} // <-- Also, you foget closing `}` here
</script>

<form id="statusUpdate" action = "whosout.php" method="post"> 
<input type="text" id="statusForm" onblur="saveStatus()" 
placeholder="<?php if($status!=null){ echo '&lsquo;'.$status.'&rsquo;';}
else { echo 'Enter your status here.';}?>"> 
</form>

Not error, but advice:

Also, note this: you used jQuery ajax function, so use jQuery in other cases too (you used pure JavaScript instead).

You getting value this way:

var status = document.getElementById("statusForm").value;

Use jQuery syntax instead:

var status = $("#statusForm").val();

Additional info

As, @Utkanos noticed in comments to this answer:

...all of which would be obvious if you look in the error console.

You have to use some debug tool, like FireBug or DevTools (Chrome, also in Chrome you can use CTRL+SHIFT+J). Not have to. You MUST do it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Submiting a form using PHP

From Dev

Submiting form using javascript

From Dev

Submiting Symfony 2 embedded form with file using ajax

From Dev

Submiting Symfony 2 embedded form with file using ajax

From Dev

Form Submission not working second time after submiting using Jquery and Ajax

From Dev

Submiting Form using Jquery and Ajax without action attribute

From Dev

Ajax submiting a form with enter and onclick

From Dev

Cannot prevent an ajax loaded form from submiting

From Dev

Why does the second form disappear after submiting?

From Dev

how can i show echo result in same page of submiting form using ajax

From Dev

Cannot get field data in controller from view when submiting form using ajax

From Dev

Cannot get field data in controller from view when submiting form using ajax

From Dev

Why is my ajax form not working?

From Dev

Get return when submiting form using jquery (without refresh)

From Dev

JQuery/PHP form not Submiting

From Dev

submiting form html django

From Dev

Materializecss form with angularjs not submiting

From Dev

Why is my AJAX form still loading my PHP page?

From Dev

Submiting a form with jquery/AJAX isn't working when clicking the submit button

From Dev

Submiting a form after clicking the submit button to perform an AJAX query, unexpected results

From Dev

Form not submiting on chrome but in firefox submitting

From Dev

Self-submiting form redirect

From Dev

submiting form on div click with js

From Dev

Why isn't my form working correctly when trying to post something using Ajax and an external PHP file, which is receiving two strings?

From Dev

Why is my typeahead form field not working after AJAX render?

From Dev

Validating form input before submiting form

From Dev

submiting python scripts using qsub

From Dev

Why can't I get form inputs using ajax and laravel

From Dev

Node JS redirection after submiting a form

Related Related

  1. 1

    Submiting a form using PHP

  2. 2

    Submiting form using javascript

  3. 3

    Submiting Symfony 2 embedded form with file using ajax

  4. 4

    Submiting Symfony 2 embedded form with file using ajax

  5. 5

    Form Submission not working second time after submiting using Jquery and Ajax

  6. 6

    Submiting Form using Jquery and Ajax without action attribute

  7. 7

    Ajax submiting a form with enter and onclick

  8. 8

    Cannot prevent an ajax loaded form from submiting

  9. 9

    Why does the second form disappear after submiting?

  10. 10

    how can i show echo result in same page of submiting form using ajax

  11. 11

    Cannot get field data in controller from view when submiting form using ajax

  12. 12

    Cannot get field data in controller from view when submiting form using ajax

  13. 13

    Why is my ajax form not working?

  14. 14

    Get return when submiting form using jquery (without refresh)

  15. 15

    JQuery/PHP form not Submiting

  16. 16

    submiting form html django

  17. 17

    Materializecss form with angularjs not submiting

  18. 18

    Why is my AJAX form still loading my PHP page?

  19. 19

    Submiting a form with jquery/AJAX isn't working when clicking the submit button

  20. 20

    Submiting a form after clicking the submit button to perform an AJAX query, unexpected results

  21. 21

    Form not submiting on chrome but in firefox submitting

  22. 22

    Self-submiting form redirect

  23. 23

    submiting form on div click with js

  24. 24

    Why isn't my form working correctly when trying to post something using Ajax and an external PHP file, which is receiving two strings?

  25. 25

    Why is my typeahead form field not working after AJAX render?

  26. 26

    Validating form input before submiting form

  27. 27

    submiting python scripts using qsub

  28. 28

    Why can't I get form inputs using ajax and laravel

  29. 29

    Node JS redirection after submiting a form

HotTag

Archive