I'm doing a few ajax function over MG, the problem is that is taking
for ever to get the response from the back-end. I'm receiving
everything as JSON, I'm not sure if this is the normal speed for MG or
I'm doing something wrong.

Thanks in advance for any hint that you can provide.

JS:

function applyAjaxCoupon(code){
                         var s = new Array();
                                s['total']= 0;
                                s['status'] = 'error';
                                s['type'] = 'rejected';

                         $.ajax({ dataType: "json", async: false, data:
"action=applycoupon&code="+code, success: function(data){
                                                                                
                                        s['total']= data['TOTAL'];
                                                                                
                                        s['status'] = data['STATUS'];
                                                                                
                                        s['type'] = data['TYPE'];
                                                                                
                                        }
                        });

                         return s;

                }


VIEW:
<cfsilent><cfset event.copyToScope(variables,"xe_receiveformat,json") /
>
<cfset submit = event.linkTo(xe_receiveformat) />
<cfset ErrorStruct = viewstate.getValue("ErrorStruct", structNew()) />
</cfsilent>
<cfoutput>#json#</cfoutput>


CONTROLLER:
        if(action eq 'applycoupon'){

                        var code = arguments.event.getValue("code");

                        s.status = 'rejected'; // rejected 
#session.courses[1].EVENT_ID#
                        s.type = 'error';
                        s.total = code;

                        var CouponsService = getModelGlue().getBean( 
"CouponsService");
                    var q =
CouponsService.getCoupon(code,session.courses[1].EVENT_ID);
                        s.event = session.courses[1].EVENT_ID;

                        if( q.recordcount gt 0){

                                s.status = 'approved';
                                s.type = 'amt';

                                session.coupon = code ;

                                 if(q.coupon_type eq 2 )
                                {
                                        var ofService = 
getModelGlue().getBean("otherFunctionsService");
                                var ct = ofService.getCartTotal();

                                        s.ct = ct;
                                        s.amt_off = q.AMT_OFF;
                                        s.total = DecimalFormat((ct * 
(q.AMT_OFF/100)));

                                }else{

                                        s.total = q.AMT_OFF ;


                                }

                        }


                }

        s = serializeJSON(s);
        arguments.event.setValue( "json", s );

MODEL:

<cffunction name="getCoupon" access="public" output="false"
returntype="query">
   <cfargument name="code" type="any" />
   <cfargument name="event_id" type="any" />

   <cfquery name="CouponQuery"
datasource="#getAppConfig().getConfig().dsn#">
         select * from xxutpa_internetservices.ER_Coupons WHERE
EVENT_ID = #event_id# and ( sysdate > STARTDATE and sysdate <
ENDDATE ) and AMT_OFF > 0 and CODE = '#code#'
   </cfquery>

   <cfreturn CouponQuery />

</cffunction>

<cffunction name="getCartTotal" access="public" output="false"
returntype="numeric">

           <cfset var total = 0 />

                <cfloop from="1" to="#arrayLen(session.courses)#" index="ind">
                        <cfif session.courses[ind].quantity gt 0>
                                <tr><td colspan=7><span
class="font-14pxB">#session.courses[ind].title#</span></td></tr>
                                <cfif session.courses[ind].quantity gt 0>
                                        <cfset 
theprice=session.courses[ind].price>
                                        <cfset innerarray = 
session.courses[ind].students />
                                        <cfloop from="1" 
to="#arrayLen(innerarray)#" index="ind2">
                                                <cfset total = total + theprice 
/>
                                        </cfloop>
                                </cfif>
                        </cfif>
                </cfloop>

                <cfreturn total />
        </cffunction>

-- 
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog

You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en

Reply via email to