ajaxCallMethod("http://www.myserver.com/mypage.cta","testit",['1001','1003'], function (result) {alert(result);}, onPageError);
On the server, I see the parameters in the cformvariables property, but the method isn't being sent, as in
is returning an empty string. What am I doing wrong?lcMethod = Request.QueryString("Method")
Allen
The links I posted have both client and server side code (first one) and it works with 'classic' Web Connection apps. Just set up one method in a Process class that uses wwJsonService and point it at the class that has the methods that you want to call via AJAX. This can be the same process class (this) or another class instance you create. The first example shows how this is done.
FUNCTION JsonCallbacks() lcMethod = Request.QueryString("Method") *** You don't have to create a new object - you can also use THIS *** But using a separate object ensures you only expose methods *** you care to expose rather than Process methods lotarget = THIS && Process class methods will be called *** Instantiate the Json Service loService = CREATEOBJECT("wwJsonService") *** Response is ALWAYS JSON unless there's a hard server error Response.ContentType = "application/json" *** Simply call the specified method - *** The service will pull out method parameters from REQUEST *** Note the service will handle errors internally and return *** a JSON error object lcJSON = loService.CallMethod(Request,loTarget,lcMethod) *** Write out the result from CallMethod which returns the JSON for the method *** or a JSON Error object if the call failed Response.Write( lcJSON ) Response.End() RETURN ENDFUNC * JsonCallbacks
*** Process method that can be called via AJAX
FUNCTION HelloWorld(lcName)
RETURN "Hello " + lcName + " Time is: " + TIME()
Then to call this from the client you would use (assuming a .wwd scriptmap):
ajaxCallMethod("JsonCallbacks.wwd","HelloWorld",["rick"], function(result) { alert(result); }, onPageError);
which should produce: "Hello Rick. Time is 10:15am".
Basically you call the JsonCallbacks method and tell it to run the HelloWorld method and pass a single parameter of "rick" in an array. You can pass multiple parameter values [parm1,parm2,parm3] if that's what you need for the method call.
The server side code simply returns a FoxPro value (a string here), object, array or cursor. Cursors can be returned by using special syntax.
Of course you can do more interesting stuff here like return objects or cursor data from the method.
For example if you want to return a cursor you can use:
************************************************************************ * GetCustomerList **************************************** FUNCTION GetCustomerList SELECT Company,CareOf,Pk FROM TT_Cust ; ORDER BY COMPANY INTO CURSOR TQUERY *** Return the cursor as a result. NOTE we have to leave it open *** for the parser to create it. The parser wiil close it RETURN "cursor:TQuery"
On the client you'd then use:
ajaxCallMethod("JsonCallbacks.wwd","CustomerList",[], function(customers) { alert(customers.Rows[0].Company); // echo first customer's company }, onPageError);
Lots of things you can do with this and it's easy to do regardless of whether you use the new WCF or process class methods.
+++ Rick ---
I like the looks of the jQuery stuff. What would have to be done to our process file to allow the AJAX calls to process? Do you have any examples of the server side of the AJAX calls?
We have a website, totally independent of ours, wanting to send items from a shopping cart to our shopping cart and they're wanting to do it via AJAX. Our process file is all in the classic Web Connection style, so what do we need to do to allow the AJAX calls to process?
Allen
Hi Allen,
You don't need ASP.NET to do AJAX with Web Connection. It supports AJAX callbacks both for the new ASP.NET style Web Control Framework (which is a little easier as there are controls that handle all the script dependencies and a bit of startup code for you) as well as classic Web Connection using templates and raw HTML.
Basically, we provide ww.jquery.js which is a jQuery helper library that makes it real easy to make AJAX calls, or you can also use jQuery (or any other JavaScript library) directly. All of this functionality is baked into the latest versions of Web Connection...
Here are some links you might want to check out (from the Web Connection 5.x docs):
- How to run JSON Ajax Requests without the Web Control Framework
- ww.jquery.js ajaxCallMethod()
- ww.jquery.js ajaxJson
- ww.jquery.js ajaxLoadHtml
Of course you can always use jQuery directly to load HTML or JSON data into the client as well.
Hope this helps,
+++ Rick ---
Years ago, we started using Webconnect using expandtemplate with standard html pages as our templates. Everything has worked fine and we've continued to use this process for everything web related. We now need to add some AJAX controls to our website, but I have no idea how to mix it in with our current coding practices. I've seen some examples here using AJAX, but everything seems to be asp.net based, so I'm not really sure where to start here. I don't use any asp.net anywhere, so I don't know how to use it at all. Where would be a good place to start using AJAX? Any pointers or suggestions?
Thanks!