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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:44:49+00:00 2026-05-25T06:44:49+00:00

I am trying to open an overlay on a button click. The button has

  • 0

I am trying to open an overlay on a button click. The button has associated with it an ajax call, which if returns an error should open an overlay, but on success the overlay does not open.

What happens is that the overlay opens regardless of success/error in ajax response. It opens on button click, not on ajax response. What am I missing here???

Here is what I am trying…

//Overlay setup
$('#PostQuestion').overlay({
    target: "#template"
});

//Ajax call setup
$('#PostQuestion').click(function() {
    $.ajax({
        url: '/ask_away',
        dataType: "json",
        data: {question: 'something'},
        type: 'POST',
        cache: false,
        success: function(response) {
            alert("It was a success");
        },
        error: function(request, error) {
            $('#PostQuestion').data('overlay').load();
        }
    });
});

<!-- HTML Here -->
<div id="template">You got an error</div>
<div id="PostQuestion">Ask Question</div>
  • 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-25T06:44:50+00:00Added an answer on May 25, 2026 at 6:44 am

    The reason the overlay is showing regardles of success/error of ajax call is because this:

    $('#PostQuestion').overlay({
        target: "#template"
    });
    

    basically defines click handler for #PostQuestion div to open an overlay. So once you click PostQuestion div you not only sending the ajax but also showing the overlay (which is as I said result of the code snippet above).

    To make it work as desired check the code below. Just one more quick side-note – even if the ajax call return 200 OK, but not a proper json data the error handler will be used, so keep that in mind while developing.

    $(function() {
                //Overlay setup
                //select the overlay element in the jQuery selector and not the trigger element
                $("#template").overlay();
    
                //Ajax call setup
                $('#PostQuestion').click(function() {
                    $.ajax({
                        url: '/ask_away',
                        dataType: "json",
                        data: {question: 'something'},
                        type: 'POST',
                        cache: false,
                        success: function(response) {
                            alert("It was a success");
                        },
                        error: function(request, error) {
                            $("#template").data('overlay').load();
                        }
                    });
                });
            })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use ClearBox JS to open an overlay onload, but my
I trying to open C: directly with FileStream without success: new FileStream(C:, FileMode.Open, FileAccess.Read,
when trying to open report server url http://<>/Report server i am getting error /
I am trying to do something I think should be fairly simple, but I
I'm trying to open Shadowbox from within a radio button onclick event on a
I'm trying open a txt file and read it, but I'm getting a type
im trying to open a popup with nothing but the content using javascript in
I´m trying to open street view in UIWebView but it doesn´t work. I can
I'm trying to open the editor associated with 'txt' files - here's the rub
I am trying open a new window using url.Action. And the new Window url

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.