Home > DeveloperSection > Forums > set value out of mootools request
Alex Leblois
Alex Leblois

Total Post:67

Posted on    June-20-2013 3:02 AM


 1 Reply(s)
 1058  View(s)
Rate this:
Hi Expert,

I want to perform a AJAX request in a function and then return the result of the request (using mootools). The request and the response are working like I want, but the variable is still 0.

here my function:

function recalcPrice(baseprice, rclass, count){
    var newPrice = 0;
    var request = new Request.JSON({
        method: 'post',
        url: 'controller/xhr_request.php',
        async: false, //UPDATE: that line solves the problem
        data: {
            'performaction' : 'calcNumberPrice',
            'baseprice'     : baseprice,
            'class'         : class,
            'number'        : count
        timeout : 5000,
        onComplete: function(response) {
            console.log('response=' + response);
            if(response.status == 'success'){
                console.log('price = ' + response.price);
                newPrice = response.price;
    return newPrice;

console shows that the price has calculated correctly, but the variable newPrice is not changed...

The problem is allready known in SO but shouldn't this solution made it?

Any help on above is really appreciated.

Sumit Kesarwani

Total Post:378

Posted on    June-20-2013 6:58 AM


set asynchronous request to false as following

async: false,

I hope now it's working.

Don't want to miss updates? Please click the below button!

Follow MindStick