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

  • SEARCH
  • Home
  • 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 6611273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:56:57+00:00 2026-05-25T19:56:57+00:00

I am using jquery post, and somehow it seems the post get posted twice.

  • 0

I am using jquery post, and somehow it seems the post get posted twice. I am testing this on Android Broswer. Very wired. Does anybody know why? Is this a jquery bug or something?

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <script type="text/javascript" src="vendor/jquery-1.5.js"></script>
    <title>Test Runners</title>
</head>
<body>

<h1>Test Runner</h1>
<script type="text/javascript">
    post_result = function() {
        console.log("post_result is called!");
        $.post( 'http://192.168.2.3:8001',  { 'jasmine-url' : "test url" ,'jasmine-content' : "test content" } )
            .success(function() { alert("second success"); return true; })
            .error(function() { alert("error"); return true; })
            .complete(function() { alert("complete"); return true; });
    }
</script>
<a href="javascript:post_result()">post result</a>
</body>
</html>

More info:

Made some changes to original post.

Actually in Chrome, it only made two request when we first make post request, and one is OPTION method, and another one is POST.

But on Android browser, the same code is make two POST request every time. I think there might be something wrong about JQUERY with Android browser. Anybody is aware of this?

  • 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-25T19:56:58+00:00Added an answer on May 25, 2026 at 7:56 pm

    Not sure why it would post twice, but I note several issues with your code.

    First of all, we’re long past inline JavaScript and executing JavaScript inside the href-attribute is a big no no (there’s the onclick attribute for that, but thats another dinosaur you shouldn’t touch). There’s loads of great JavaScript frameworks out there that makes it dead easy to bind to events such as click.

    Secondly, your post_result function is defined as global and lacking a semicolon.

    To rectify the above, the following snippet should be put in the head or in a separate file. It will do the same, but in a more jQuery-ish way following good practices.

    JavaScript

    // Short-hand for DOM-ready
    $(function(){
        // Define variable in local scope to store request
        var request;
    
        // Bind to the click event to all anchors with the class post-results
        $("a.post-results").click(function(e){
            // Prevent default behavior. I.e. stop browser from navigating
            e.preventDefault();
    
            // If there's a previous request, abort it. No need for two.
            // You could also return here if you want to wait for the first
            // one to finish.
            if (request) { request.abort(); }
    
            // Let's fire off the request and store it for future reference
            request = $.post(
                    'http://192.168.2.3:8001',
                    {
                        "jasmine-url": "test url",
                        "jasmine-content": "test content" 
                    }
                )
                .success(function(res) {
                    console.log("second success", res);
                })
                .error(function(xhr, err) {
                    console.log("error", err);
                })
                .complete(function() {
                    console.log("complete");
                    // Set request var to null
                    request = null;
                });
        });
    });
    

    HTML

    <a class="post-results" href="#">Post result</a>
    

    To make sure that jQuery is loaded properly, you should load it from an established public CDN such as Google Libraries API.

    I also urge you to jump to the HTML5 doctype, which is backwards-compatible with HTML4. Just switch your doctype to <!DOCTYPE html> and you’re good to go.

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

Sidebar

Related Questions

How to pass multiple checkboxes using jQuery ajax post this is the ajax function
hello frieds this is how i usually post a variable using Jquery.. $.post(include/save_legatee.inc.php, {
I'm using jQuery to post a form to a php file, simple script to
I am using JQuery to post with AJAX to another ASP page. Do I
I'm using jQuery to post to an ASP .NET Web Service to implement a
I have written a form using the jQuery .post() function to post the data
I'm using jquery ajax to post updates back to my server. I'm concerned about
I am using jQuery to make a POST to a PHP file with the
I'm using jQuery to make an Ajax call using an Http Post in ASP.NET
I am posting to the server using jquery ajax using $.post. After server returns

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.