Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6756843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:34:23+00:00 2026-05-26T13:34:23+00:00

Stuck with a jquery ajax form submission! Here’s the code snippet: Javascript/ HTML Code:

  • 0

Stuck with a jquery ajax form submission! Here’s the code snippet:

Javascript/ HTML Code:

<form action="">
<button type="submit" class="submit-button-minus" id="submit-minus" name="submit-minus"><span class="hide-text"></span></button>                
</form>

<form action="">
<button type="submit" class="submit-button-plus" id="submit-plus" name="submit-plus"><span class="hide-text"></span></button>
</form>

<!--store current page id from php variable into javascript variable-->
<?php echo "<script> jsPageID = " .$page_id. ";</script>"; ?>                   
<?php echo "<script> jsUsername = '" .$_SESSION['username']. "' ;</script>"; ?>     


<script type="text/javascript">
$('document').ready(function(){

jsPageID = parseInt(jsPageID); 
$('#submit-minus').click(function(){
jsPlusOrMinus = "minus";                    
ajax_painting_rating(jsPlusOrMinus, jsPageID, jsUsername);                  
});

$('#submit-plus').click(function(){
jsPlusOrMinus = "plus";
ajax_painting_rating(jsPlusOrMinus, jsPageID, jsUsername);
});

function ajax_painting_rating(jsPlusOrMinus, jsPageID, jsUsername)
{
$.get(
'ajax-painting-rating.php', 
{plus_or_minus: jsPlusOrMinus, page_id: jsPageID, user_name:jsUsername }, 
function(data){     
$('#rating-value').html(data);
}
);
}

});

</script>

Now here’s the PHP code:

<?php
include("include_db_connection.php");

$get_plus_or_minus = $_GET['plus_or_minus'];
$get_page_id = $_GET['page_id'];
$get_user_name = $_GET['user_name'];

if($get_plus_or_minus == "plus")
{

    $rating=1;
    $rating_insert_query =  "INSERT INTO ..............";       

    $rating_insert_result = mysqli_query($db_conn, $rating_insert_query);
}

if($get_plus_or_minus=="minus")
{

    $rating=-1;
    $rating_insert_query =  "INSERT INTO ..............";       
    $rating_insert_result = mysqli_query($db_conn, $rating_insert_query);
}

/* more queries here....*/  
/*this is what i will be returning back from the server, to the ajax request*/

echo $FINAL_RESULT;

?>

Now, when I try executing the above code, the form “sometimes” gets submitted to db. I cant think of a reason for why the “sometimes”.

Also, there is some data that is getting appended to the url somehow, after the request is processed. Example: If the original url of the webpage, before making the ajax request is something like “page.html?id=6” then, on executing the ajax request, the page url gets appended as below:

“page.php?id=6&submit-minus=” (if the submit-minus button was used for invoking the ajax request)

I do not understand why the submit-minus thing is getting appended to the url, and also whey only rarely the data is getting inserted successfully to the db.

Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:34:24+00:00Added an answer on May 26, 2026 at 1:34 pm

    The query vars submit-minus and submit-plus are getting appended to the url because you are doing a GET, and GET will take any form variables on a submit, and append them to the URL.

    I can’t see enough of your database code to tell you why it sometimes works and sometimes does not, but you will only write to the database if $get_plus_or_minus is set. So, if your url says “submit-minus=” without any value, you would not write to the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three forms and using this jquery function $('form').submit(function() { $.ajax({ type: $(this).attr('method'),
I'm kind of stuck with this pretty simple (I'm sure) jQuery/Javascript issue. Here's the
I'm posting a form to an MVC action using jquery Ajax. Server side, I
I'm currently using ajax and jquery to update search results with a form that
Im stuck with a ajax function im creating. Here is the deal, I have
I am doing the following: <script type=text/javascript> $(function(){ $(#ipad).submit(function() { $.post(ipadcheck.php, $(#ipad).serialize(), function(data) {
I am trying to learn making ajax calls using jQuery. But I am stuck
I'm basically just trying to submit a form through AJAX and want to show
Currently having problems with jQuery Ajax calls. It's stuck at beforeSend , no alert
seems like I'm stuck with jQuery tabs. I'm trying to pass selected tab name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.