javascript - why is my form not submiting using ajax -


is a bit of a selfish question but I'm actually starling with Ajax, so I need some help. Basically I'm trying to update and using the database using the 'onblur' function using SQL database. My code heres:

code at 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 = "  

and the code at SaveStatus.php

  & # 39; & lt;? Required 'core.php'; 'connect.php' is required; $ status = $ _POST ['feed_id'] ; $ IdPerson = $ _SESSION ['user_id']; $ query = "Update person SET status = '" .mysql_real_escape_string ($ sn '' IdPerson = '$ idPerson' "; $ query_run = mysql_query ($ query) ;? & gt;   

At this time SQL database does not get updated when I click on the input box Any help would be great!

Answer: < Ol>

  • You have to delete the script and the HTML output
  • You forget the ; .You $ Ajax block must be closed
  • you } close the task saveStatus () .

    Code:

      & lt; Script & gt; Save functionStats () {var status = document.getElementById ("statusForm") Values; $ .ajax ({url: 'saveStatus.php', type: 'post', data: 'feed_id =' + status, success: function (result) {}}); // & lt; - Besides, you forget ``); 'Here} // & lt; - Also, you have to```t here & lt; / Script & gt; & Lt; Form id = "statusUpdate" action = "whosout.php" method = "post" & gt; & Lt; Input type = "text" id = "statusForm" onblur = "saveStatus ()" placeholder = "  

    No error, but advice:

    In addition, note: you have the jQuery AJAX function Use jQuery, so in other cases also use jQuery (you have used pure javascript instead).

    You are getting the value in this way:

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

    Use jQuery syntax instead:

      var status = $ ("#formform"). Val (); In the form of   Additional Information   

    , @Utanos found the comment on this answer:

    .. If you use the Error Console If you look in, then all will be clear.

    You have to use some debugging tools, such as FireBug or DevTools (Chrome, in Chrome also you can use CTRL + SHIFT + J). not have to. You should do it

  • Comments

    Popular posts from this blog

    c - Mpirun hangs when mpi send and recieve is put in a loop -

    python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

    java - Unable to get JDBC connection in Spring application to MySQL -