Aspects of AJAX: How to setup a new AjaxEngine web projectI was asked how to setup a web project that uses the AjaxEngine so here is step by step tutorial for a minimal Ajax web project that calls a server side web service: 1. Create a new web project (I prefer using c#) or use your existing web project.I started with a new project and named it "mini". There is nothing special that you have to set up. It even works without a web.config. 2. Copy the ajaxcore folder to your project.You can find this folder and the files on sourceforge http://sourceforge.net/projects/ajaxengine/ For this project you only need the following core files GetJavaScriptProxy.aspx: the JavaScript proxy generator
That’s all you have to do to prepare the web project to use the core part of the AjaxEngine. I suggest you use the ajaxcore folder 3. Create a folder named "/calc"This folder will contain the minimal web application by using a web form and a web service. I guess you don't implement pages in the root folder of your web application so I follow this best practice here too. 4. Implement a service /calc/WebService1.asmxThere is only one method we need so here is some c# code: using System.ComponentModel;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace mini.calc {
///
5. Create a new page named WebForm1.aspx in the calc folderI just use the new item wizard from visual Studio to do this so the typical elements are there already.
6. include the ajax.js:<script src="../ajaxcore/ajax.js" type="text/javascript"></script> The ajax.js file reference should be included in the <head> element. 7. include the proxy for the webservice:<script src="../ajaxcore/GetJavaScriptProxy.aspx?service=/calc/WebService1.asmx" type="text/javascript"></script> This script include should also be included in the <head> element and will make the just implemented webservice and webmethod available through the JavaScript object proxies.WebService1.Add. 8. Implement the User interfaceA minimalist UI means just 3 fields and some text.
<input id="sum1" type="text" /> + <input id="sum2" type="text" /> = <input id="result" type="text" /> 9. Implement the JavaScript codeThis is the trickiest part of it, but it's simple too:
<script type="text/javascript"> var sum1_obj = document.getElementById("sum1"); var sum2_obj = document.getElementById("sum2"); var result_obj = document.getElementById("result"); var sum1_val = ""; var sum2_val = ""; window.setInterval(window.checkValues, 200); function checkValues() { if ((sum1_obj.value != sum1_val) || (sum2_obj.value != sum2_val)) { sum1_val = sum1_obj.value; sum2_val = sum2_obj.value; result_obj.value = proxies.WebService1.Add(sum1_val, sum2_val); } // if } // checkValues </script> 10. And that's all
Start the Web Form and see how it works. Labels: AJAXEngine |
The bookThe book "Aspects of AJAX" is available in PDF format at: Sample WebSiteThe samples as well as the complete source code can be found on this web site:
http://www.mathertel.de/ DownloadsAJAX.zip (180 kByte) This Zip-File contains the ASP.NET 2.0 web project that builds this side. All samples and Controls are included. AJAXEngine.zip (80 kByte) This Zip-File contains the core files of the AJAX engine and the AJAX controls. License
Recent posts:OpenAjax Call-to-Action to Ajax Developers for Bro... Data bound fields for Ajax forms Building menus with OpenAjax events More OpenAjax compatible components Passing values around with OpenAjax events Using OpenAjax events for building data-centric an... AjaxEngine is now full based on the OpenAjax speci... A alternative to JSON is available: web services Calling web services with structured parameters fr... Tags: Ajax Javascript webservices soap wsdl xmlhttp |
0 Comments:
Kommentar veröffentlichen
Links to this post:
Link erstellen
<< Home