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 6621563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:16:55+00:00 2026-05-25T21:16:55+00:00

I use a function to post result via Ajax. When I test to see

  • 0

I use a function to post result via Ajax. When I test to see if the function was called I add an alert. Everything works fine, but as soon as I remove alert my results are not posted… What’s causing it?

function SendInvitesF(invType, invWho, projID) {            
    $.ajax({
        url: "ajax.php",
        type: POST",
        data: "op=sendInvites&inviteMsgType="+invType+"&invitees="+invWho+"&proj="+projID   
    });
    alert("test "+projID) // test alert <<<
}

$("#btnSend").click(function() {
    if($("#customMsg").attr("checked")) {               
        var invType = "custom";
    } else {
        var invType = "default";
    }
    var invWho = $(".radioB:checked").val();
    var projID = $("#testID").val();

    SendInvitesF(invType, invWho, projID);
});
  • 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-25T21:16:56+00:00Added an answer on May 25, 2026 at 9:16 pm

    I suspect that you are calling this function in the onclick or onsubmit event and you are not canceling the default action by returning false. Also you are not properly url encoding any of your parameters. To do this use the data hash:

    function SendInvitesF(invType, invWho, projID) {            
        $.ajax({
            url: 'ajax.php',
            type: 'POST',
            data: { 
                op: 'sendInvites',
                inviteMsgType: invType,
                invitees: invWho,
                proj: projID   
        });
        return false;
    }
    

    and then if you are calling this inside the onclick of an anchor:

    // I guess btnSend is a submit button or an anchor so make sure
    // you cancel the default action by returning false from the click
    // callback
    $('#btnSend').click(function() {
        if ($('#customMsg').attr('checked')) {               
            var invType = 'custom';
        } else {
            var invType = 'default';
        }
        var invWho = $('.radioB:checked').val();
        var projID = $('#testID').val();
    
        return SendInvitesF(invType, invWho, projID);
    });
    

    Notice how we are returning false and thus canceling the default action which would be a redirect and of course not leaving the time for the AJAX request to execute. When you put an alert at the end of the function this stops any script execution and the AJAX call has the time to hit the server.

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

Sidebar

Related Questions

I'm trying to use $.post within a function, get the results, then return the
I use jquery post function to go to server and bring the link to
I want to use this function: http://www.frankmacdonald.co.uk/php/post-to-wordpress-with-php.html Its used to post to Wordpress using
quick question, is it secure to use the jQuery.post function in jQuery to pass
I use htmlspecialchars function in my string. But, I don't want to clean them;
So Im trying to use jquery's .post function to submit a form and return
I could use some help complying with Django's CSRF protection mechanism via my AJAX
Here a sample use case: I request a simple form via an ajax request.
Trying to use fileReader.readAsBinaryString to upload a PNG file to the server via AJAX,
This is my code: $.post('<?php echo site_url('channel_partners/get_cp_text'); ?>', {cp_lang: language}, function(data) { alert('icon: '

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.