eZ Community » Forums » Developer » ezjscore/call status
expandshrink

ezjscore/call status

ezjscore/call status

Monday 09 February 2015 7:18:32 pm - 3 replies

Here I am, once again...

What I need this time is: How can I get the status "ok" from an ezjscore/call

$.ez( 'ezjscmyclass::ezmyfunctioninit', args, function( data ) {
        if ( data.error_text ) {        
            ...data.error_text
        }   
        else {
            ...data2.content
        }
 });

Since I am calling the function within a loop, I need to loop to the next call only when the previous call has returned the status of "ok 200".

But, somehow, it seems so hard to me to get this call status. And data.content is not enough, here.

Is there a way to get the server response on a tpl level?

Thanks, indeed!

Modified on Friday 13 February 2015 11:20:59 pm by Lo' F.

Tuesday 10 February 2015 12:49:51 pm

All's well that ends well!

Got a way and very happy to share!

Instead of calling jQuery.ez I switched my attention to to Y.io.ez and passed all the parameters I needed within the call, wrapped it into a function to be called the first time and then iterate to the function iself to move to the next item until the set limit.

offset = 0;
interval= 1;
limit = 0;
loop_times = 50;
i = 0;
 
myajaxcall(timestamp, offset, i);
 
function myajaxcall(timestamp, offset, i) {
    YUI( YUI3_config ).use('io-ez', function( Y ) {
        Y.io.ez( 'ezjscmyclass::ezmyfunctioninit::' + sourceurl + '::' + timestamp + '::' + offset + '::' + limit + '::' + i + '::' + now, {
            on: {success: function(id,r){
                    $("#progress").html("# " + r.responseJSON.content + ' di ' + loop_times);
                    offset = offset+interval;
                    i++;
                    if(i < loop_times) {
                        myajaxcall(timestamp, offset, i);
                    }
                },
                failure: function(){
                    $("#result").append('Error accourred while processing item # <b>' + offset + '</b>');
                    offset = offset+interval;
                    i++;
                    if(i < loop_times) {
                        myajaxcall(timestamp, offset, i);
                    }
                }
            }
        });
    });
}

This way the ajax calls are processed one at a time and, on screen I can get the ouput i needed to see whether it successes or fails.

;D

Modified on Tuesday 10 February 2015 1:03:17 pm by Lo' F.

Tuesday 10 February 2015 1:37:19 pm

You may want to use the sync option rather than recursion.  It is simpler, achieves the same result and will probably run faster.

http://yuilibrary.com/yui/docs/io/

Coded to use a simple while loop (not tested)

var offset = 0;
var interval = 10;
var limit = 0;
var iterations = 50; // loop_times
var i = 0;
 
while (i < iterations) {
    YUI( YUI3_config ).use('io-ez', function( Y ) {
        Y.io.ez( 'ezjscmyclass::ezmyfunctioninit::' + sourceurl + '::' + timestamp + '::' + offset + '::' + limit + '::' + i + '::' + now, {
            on: {success: function(id,r){
                    $("#progress").html("# " + r.responseJSON.content + ' di ' + iterations);
                    },
                   failure: function(){
                    $("#result").append('Error accourred while processing item # <b>' + offset + '</b>');
                    }
                  },
            sync: true
    });
    offset = offset + interval;
    i++;
}

Tuesday 10 February 2015 4:18:41 pm

Thank u, Betsy, your solution rocks! Works like a charm and keeps the code neat and tidy!

Thanks happy.gif Emoticon

Modified on Tuesday 10 February 2015 10:20:44 pm by Lo' F.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from