Using webservice calls with multiple parameters

Posted by: Aspects of AJAX, on 21 May 2007 | View original | Bookmarked: 0 time(s)

The restriction that the AJAXEngine supported only methods with one parameter had been a topic to some postings in the blog and also to some good comments with good solutions.

Because the problem was only restricted by the AJAX Engine itself and not by the underlying JavaScript proxy layer I looked for a small and neat solution and finally found that the often overlooked Javascript method apply

helps here.

The implemented way of passing more than one parameter is (like suggested) to use an Array as a return value of the prepare function. Because arrays are also supported as a parameter to the called method itself a extra hint is used to distinguish these 2 scenarios.

Here is how to implement the prepare method for this case:

prepare: function (ds) { 
  var p = new Array();
  p[0] = ajaxForms.getData(ds.form);
  p[1] = "name";
  p.multi = true; // the hint for the ajax Engine
  return(p);
},

The changes in the AJAX Engine layer is only a condition check and a call using the apply method:

// start the call
ca.call.func = ajax.Finish;
ca.call.onException = ajax.Exception;
if ((data.constructor == Array) && (data.multi != null)) // 19.05.2007
  ca.call.apply(ca, data);
else
  ca.call(data);

If you want to use this feature, you can download the ajax.js file directly. A complete version will be available some day soon including new samples and features.

Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: Ajax | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 954 | Hits: 74

Similar Posts

  • How to setup a new AjaxEngine web project more
  • Web.UI Navigation Controls and Web Services more
  • Getting JavaScript and ASP.NET talking (outside of AJAX) more
  • How to... use Class Libraries with ASP.NET AJAX like AjaxPro more
  • Web Service Data Loading with Navigation Controls more
  • New Grid Feature: WebService Running Mode more
  • UriTemplate 101 more
  • How to Create a WebService Based on a Workflow more
  • Invoke a WebService from a Workflow more
  • C# Reflection Part 6 more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD