[CLOSED] for submit to webservice

  1. #1

    [CLOSED] for submit to webservice

    I am in trouble to make correct call to web service. Form values are being submitted correctly the only problem is that webservice respond in xml despite that [System.Web.Script.Services.ScriptService] is uncomment, It throws an error on response. Ext.JSON.decode(): You're trying to decode an invalid JSON String:
    for exampe
    createNewAssets: function () {
            var frm = Ext.getCmp('frmAddNewAsset').getForm();
            frm.submit({
                url: '../../stores/assets.asmx/saveNewAssets',
                cleanRequest: true,
                json: true, //it is not working 
                params: {
                    newAsset: frm.getValues(true)
                }
                success: function (form, action) {
                    Ext.Msg.alert('Success', action.result.msg);
                }
            })
    
       [WebMethod]
        public string saveNewAssets() { 
            return "{'success' : true , 'msg' : 'Success' }" ;
        }
    Last edited by Daniil; Jul 10, 2013 at 3:51 AM. Reason: [CLOSED]
  2. #2
    Hi @odyssey,

    This option
    json: true
    deals with DirectEvents and DirectMethods, it doesn't deal with form submit.

    You can use the jsonSubmit method.
    http://docs.sencha.com/extjs/4.2.1/#...cfg-jsonSubmit

    Example
    form.submit({
        url: 'some URL',
        jsonSubmit: true    
    });
    Also I think you can remove these settings:
    cleanRequest: true,
    params: {
        newAsset: frm.getValues(true)
    }
    Though, there is another problem. A JSON WebService response always contains "d" as a root. A form can't interpret it and will always fire a failure handler. Well, you can listen to a failure, then analyze a response. Though, personally, I would prefer to use an HTTP handler instead (ashx).

    Also you can use an XML WebService. Here is an example of possible response.
    http://docs.sencha.com/extjs/4.2.1/#....action.Submit
  3. #3
    There is another approach - using a FormPanel's ErrorReader.

    Page
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    
        <script>
            var submit = function () {
                App.FormPanel1.submit({
                    url: 'WebService1.asmx/Submit',
                    jsonSubmit: true,
                    success: function () {
                        console.log("success");
                    },
                    failure: function () {
                        console.log("failure");
                    }
                });
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:Model runat="server" Name="ErrorModel">
                <Fields>
                    <ext:ModelField Name="id" />
                    <ext:ModelField Name="msg" />
                </Fields>
            </ext:Model>
    
            <ext:FormPanel ID="FormPanel1" runat="server">
                <ErrorReader>
                    <ext:JsonReader 
                        Root="d" 
                        ModelName="ErrorModel" 
                        SuccessProperty="d.success" />
                </ErrorReader>
                <Items>
                    <ext:TextField runat="server" Text="Hello!" />
                </Items>
            </ext:FormPanel>
    
            <ext:Button runat="server" Text="Submit" Handler="submit" />
        </form>
    </body>
    </html>
    WebService
    using System.Web.Services;
    
    namespace Work2
    {
        /// <summary>
        /// Summary description for WebService1
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        [System.Web.Script.Services.ScriptService]    
        public class WebService1 : System.Web.Services.WebService
        {
            [WebMethod]
            public object Submit()
            {
                return new
                {
                    success = true
                };
            }
        }
    }
  4. #4
    Quite amazingly I could find submitted params in case where form is configured submitting json. Context.Request["Param1"] nor Context.Request.QueryString["Param1"] has any data but fiddler clearly shows that json being submitted. Strange
    Last edited by odyssey; Jul 02, 2013 at 7:57 AM.
  5. #5
    There are two approaches for a JSON WebService to get parameters.

    1. Changing a method signature to:
    [WebMethod]
    public object Submit(string Param1, string Param2, ...)
    2. Reading parameters from Request.InputStream. Here is an example, search for the "Retrieve JSON data from Request.InputStream" header.
    http://www.codeproject.com/Articles/...-AJAX-and-JSON
    Last edited by Daniil; Jul 16, 2013 at 4:20 AM.

Similar Threads

  1. [CLOSED] WebService params
    By odyssey in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Mar 06, 2013, 6:07 AM
  2. Replies: 1
    Last Post: Jul 25, 2012, 9:52 AM
  3. submit?
    By marco.amusquivar in forum 1.x Help
    Replies: 0
    Last Post: Mar 25, 2012, 7:37 PM
  4. Help with WebService and Ext.net
    By xborderland in forum 1.x Help
    Replies: 3
    Last Post: Aug 11, 2011, 11:50 AM
  5. [CLOSED] Submit gridpanel data in form submit
    By jchau in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jul 14, 2010, 7:25 PM

Tags for this Thread

Posting Permissions