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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:41:40+00:00 2026-05-20T11:41:40+00:00

I have two buttons, Save and Unsave. Typically, I had each go to a

  • 0

I have two buttons, Save and Unsave. Typically, I had each go to a PHP post page and that refreshed the page. If you clicked Save, the page would be refreshed and only Unsave would show – and vice versa.

I’m trying to do this with Ajax and jQuery. Basically, I have these:

<span style="display: <?php echo $youveSaved; ?>"><input type="button" value="Unsave" onClick="$.post('php/removeSave.php', $('#removeSave').serialize());$('#jqs').attr('value', 'Save');" id="jqs"/></span>
<span style="display: <?php echo $hasSaved; ?>"><input type="button" value="Save" onClick="$.post('php/saveCoup.php', $('#saveCoup').serialize());$('#jqs').attr('value', 'Unsave');" id="jqs"/></span>

Here’s the PHP that would normally switch them:

//$thisIsSaved would return 1 if the coupon has been saved and 0 if not
        $hasSaved = "inline";
        $youveSaved = "none";
        if($thisIsSaved > 0 && $_SESSION["loggedIn"] == 1)
            {
                $hasSaved = "none";
                $youveSaved = "";
            }
        elseif($thisIsSaved == 0 && $_SESSION["loggedIn"] == 1)
            {
                $hasSaved = "";
                $youveSaved = "none";
            }
        else
            {
                $hasSaved = "none";
                $youveSaved = "none";
            }

How could I do that without a page refresh, with pure Ajax + jQuery?

  • 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-20T11:41:41+00:00Added an answer on May 20, 2026 at 11:41 am

    You can easily do that with jQuery and jQuery’s $.ajax() method.

    See Live example: http://jsfiddle.net/rtE9J/11/

    HTML

    <button id="save">Save</button>
    <button id="unsave">Unsave</button>
    <div id="result"></div>
    

    CSS

    #unsave{display:none}
    

    JS

    $('#save, #unsave').click(function(){
    
        //maintain reference to clicked button throughout
        var that = $(this); 
    
        //disable clicked button
        $(that).attr('disabled', 'disabled'); 
    
        //display loading Image
        $('#result').html('<img src="http://blog-well.com/wp-content/uploads/2007/06/indicator-big-2.gif" />'); 
    
        //Make your AJAX call
        $.ajax({ 
            url: 'changeSave.php', 
            data: {action: $(this).attr('id')},
            success: function(d){
    
                //re-enable the button for next time
                $(that).attr('disabled', ''); 
    
                //Update your page content accordingly.
                $('#result').html(d); 
    
                //Toggle the buttons' visibilty
                $('#save').toggle(); 
    
                //Toggle the buttons' visibilty
                $('#unsave').toggle(); 
    
            },
            type: 'POST'     
        });
    });
    

    I even threw in a nice loading icon for you.

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

Sidebar

Related Questions

I have a apsx page and in that page I have two buttons called
I'm currently implementing a UIActionsheet that has two buttons. Each of the buttons save
I have one modelpopup extender, in that one textbox and two asp.net buttons(save,exit), textbox
I have an .aspx page that contains two buttons one is btnCancel and another
I have one page in HTML , there are two buttons , save and
I have two buttons for my form - a Save changes button and a
I Have two button in opportunity page one is Save which is by default
I have two buttons in my flex app next to each other, ButtonA and
I have two buttons on my MVC form: <input name=submit type=submit id=submit value=Save />
What I have here real simple activity with two buttons. When you press each

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.