Tech Rocks

Coldfusion
Java
JQuery

An online resource for latest web technologies like Coldfusion, JRun, Pro*C, JQuery, HTML5, PHP, W3C, Java, J2EE, C, C++, ORACLE, PL/SQL, MySql, Ajax, Coldbox, Fusebox, UNIX, JavaScript, NodeJS and much more...

Saturday, April 9, 2011

Ajax Post with JSON returned

Example:
function postit_3(obj) {
       
    signin_obj = null;
    url = url + '?' + (new Date()).getTime();
    username = obj("#username").val();
    password = obj("#password").val();
   
    id = "step2_container";
    showpreloader(id);
   
    obj.ajax({            
        type: 'POST',
        url: url,
        data: {returnFormat: 'json', user: username, password: password},                
        success: function(json, status) {
            //alert(json);
            var period = $("#hid_period").val();
            var productcd = $("#hid_productcd").val();
            var content = obj.parseJSON(json);
            obj.each(content, function (e) {
                if(e === "COLUMNS" && this[0] == "ERROR") {
                    $('#step2_container').load(load_url_1, function(){ alert("LOGIN ERROR!"); });
                }
                else
                if(e === "DATA")
                for(i=0; i< this.length; i++){
                   
                    //alert("RECORD: " + this[i]);
                    signin_obj = this[i];
                   
                   
                    if(signin_obj[37] >= 0) {
                        Expired = true;
                    }
                    else {
                        Expired = false;
                    }
                   
                   
                    //check additional members logic and insert leads..
                    if(signin_obj[32] == 'A') { redirect_1(); return;}
                    //check monthly sub
                    //postit_6_2(obj); Not needed any more
                    if(signin_obj[32] == 'MO') {redirect_1(); return;}
                    if(signin_obj[32] == 'MO') hideyearlymonthlytabs();
                        
                                        postit_6(obj);
                    
                                    }
            });
        },
        error: function(e){
            alert("postit() function error: "+e.statusText);
        },
        complete: function(){ /*alert("AJAX COMPLETE");*/ }
        ,cache: false
    });
}

0 comments :