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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:34:17+00:00 2026-06-04T06:34:17+00:00

A function triggers a database call which returns some Json. This CID is then

  • 0

A function triggers a database call which returns some Json. This CID is then used to stamp the newly added DOM element.

I need to retrieve / return the value of “cid” which exists within ajax success block, it will be used to update attribute.

Error
cid is not defined

//Save New Task
$("body").on('click','.icon-facetime-video',function(event){
  var new_entry = $(this).prev().val();
  var thebid = $(this).parents('tbody').prev().find('th').attr('id').split('_')[1];
  $(this).parent().addClass('tk').html('<i class="icon-eye-open"></i> '+new_entry);
  //CALL FUNCTION
  var cid = update_entry('new_tk',new_entry,thebid); //value of cid from update_entry
  $(this).parent().attr('id','cid_'+cid);
});

function update_entry(typeofupdate,new_entry,thebid){

  switch(typeofupdate){
    case 'new_tk': var action = 'new_tk';
    break;
  }

  $.ajax({
        type:'post',
        url: 'posts_in.php',
        dataType: "json",
        data: {cid : thebid, action: action, content: new_entry},
        success: function(data){
            var action = data[0],cid= data[1];
            console.dir(data);
        }
    });

  return cid;  
}
  • 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-06-04T06:34:20+00:00Added an answer on June 4, 2026 at 6:34 am

    Since AJAX is done asynchronously (hence the a in AJAX), your function returns before the AJAX call completes. You should pass a callback function into update_entry, and run it in your AJAX success handler:

    var self = this;
    
    update_entry('new_tk', new_entry, thebid, function(cid) {
        $(self).parent().attr('id', 'cid_' + cid);
    });
    
    function update_entry(typeofupdate, new_entry, thebid, callback) {
    
      switch(typeofupdate){
        case 'new_tk': var action = 'new_tk';
        break;
      }
    
      $.ajax({
            type:'post',
            url: 'posts_in.php',
            dataType: "json",
            data: {cid : thebid, action: action, content: new_entry},
            success: function(data){
                var action = data[0], cid= data[1];
                callback( cid );
                console.dir(data);
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I want to trigger an error in my interpreter I call this function:
So I have this database class in PHP and I only have 1 function
How can I achieve the following? // Resize triggers $(window).resize(function() { if (window.innerWidth <=
I ve created function and trigger as follows: CREATE OR REPLACE FUNCTION New_Ticket() RETURNS
When I pass 'this' to an anonymous function like so: MyClass.prototype.trigger = function(){ window.setTimeout(function(){this.onTimeout();},1000);
Look at this: $('form).submit(function (event) { $(':input.required').trigger('blur'); var num = $('.warning', this).length; alert(num);//Focus here!
We have a scalar function that returns a DateTime. It performs a couple of
I'm building a login form that will validate the login against a database, then
I have some jQuery that when you click the save button it triggers a
I created a code which generates content and I want to populate Wordpress's database

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.