AjaxMethod does not return value

  1. #1

    AjaxMethod does not return value

    Hi,
    I have a simple AjaxMethod that returns a string.

        [AjaxMethod]
        public String encryptCool(String val)
        {
            val = Crypto.Encrypt(val);
            string s = System.Web.HttpUtility.UrlEncode(val);
            return s;
        }
    When i debug i can see that the ajaxmethod is called and it encrypts the value s as it should be.
    i call it from a Gridpanel column,

                    <ext:Column DataIndex="id" Header="Show Document" Width="50">
                        <Renderer Fn="ShowDoc" />
                    </ext:Column>
    The js code for function ShowDoc on my page is as follows, problem is variable c returns undefined, when i remove the AjaxMethod encryptCool function and
    return the record.data.id it works. What am i missing ? Best Regards
       <script type="text/javascript">
            var ShowURL = '<a href="show.aspx?bt={0}&amp;tt={1}&amp;aid={2}"><img hspace="15" border="0" src="../../img/view.gif"/></a>';
            var ShowDoc = function(value, metadata, record, rowIndex, colIndex, store) {
                var a = record.data.bID;
                var b = record.data.aID;
                var c = Coolite.AjaxMethods.encryptCool(record.data.id); // c comes undefined here, if i remove function i get the id correctly eithout encyrption
                return String.format(ShowURL, a, b, c);
            }
        </script>
  2. #2

    RE: AjaxMethod does not return value

    Hi,


    The calling of AjaxMethod is asynchronize operation. You should listen success and failure events and handle return values. Therefore you can't use ajax method in renderer because renderer must return value*immediately but ajax method return value only after server response (it will be after renderer performing)

    See example which shows how to work with ajax methods
    https://examples1.ext.net/#/Events/AjaxMethods/Overview/



Similar Threads

  1. Replies: 4
    Last Post: Jul 25, 2012, 5:45 AM
  2. Return a parameter MVC
    By threewonders in forum 1.x Help
    Replies: 0
    Last Post: Mar 09, 2011, 12:24 PM
  3. take value of return function
    By thiefo in forum 1.x Help
    Replies: 5
    Last Post: Mar 11, 2010, 7:47 AM
  4. Replies: 2
    Last Post: Jan 08, 2010, 2:47 AM
  5. How can I get return value webservice?
    By relativ in forum 1.x Help
    Replies: 0
    Last Post: Dec 02, 2009, 4:33 AM

Posting Permissions