0
$('.updateDescriptionProduct').click( function() {
  if ( updateProductDescription(productID, description) == 'true') {
    alert('success!');
  } else {
    alert('did not update');        
  }
});

function updateProductDescription(productID, description) {
  $.ajax({
    url: '/index.php/updateProductDescription',
    global: false,
    type: 'POST',
    data: ({productID: productID, description: description}),
    dataType: 'html',
    async:false,
    success: function(msg){
      alert(msg); 

      return msg;
    }
  });
}

The function itself says true, but my click event comes back as undefined.

1
  • What exactly are you trying to do? Commented Aug 15, 2010 at 1:05

1 Answer 1

10

the return applies to the callback. Try setting a variable in the initial function and setting the value in the callback, then returning it?

function updateProductDescription(productID, description) {
    var ret = false;
    $.ajax({
          url: '/index.php/updateProductDescription',
          global: false,
          type: 'POST',
          data: ({productID: productID, description: description}),
          dataType: 'html',
          async:false,
          success: function(msg){
            ret = msg;
          }
    });
    return ret;
}

I haven't ever done an async call but it seems this should work. Let me know if it doesn't.

Sign up to request clarification or add additional context in comments.

2 Comments

But he disabled it with async:false. Otherwise he'd have to refactor it because he's doing it asynchronously.
That was it! Thanks for the quick response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.