locked
Ajax post from a jquery dialogbox issue RRS feed

  • Question

  • User136609187 posted

    Iam currently working on asp.net application and using Jquery uidialog to show customized messages.

    Based on the Jquerydialog response i want to execute server side code.

    below is the code iam using. Its giving Internal server error while posting to the url.

    Please help me out ..

    Jquery function

    function SendResultsConfirmation(message) {
            $("#divDialog").html($("<h5>" + message + "</h5>"));
            $("#divDialog").dialog({
                width: '350',
                height: '175',
                modal: true,
                draggable: false,
                resizable: false,
                buttons: {
                    'Yes': function () {
                        $.ajax({
                            type: "POST",
                            url: "SendTestResults.aspx/SendResult",
                            data: "{subject:'" + $("#appResult").val() + "'}",
                            contentType: "application/json",
                            dataType: "json",
                            success: function (msg) {
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                debugger;
                            }
                        });
    
                        $(this).dialog('close');
                    },
                    'No': function () {
                        $(this).dialog('close');
                    }
                }
    
            });
    };

    Method definition in SendTestResults.aspx.cs page

        
        [WebMethod()]
        public static void SendResult(string message)
        {
            
        }


    Please have a look
     

    Thursday, April 24, 2014 3:23 PM

Answers

  • User1918509225 posted

    Hi Chithra_lyer,

    The problem is not in the jquery ui dialogbox,it is your  function have problem.

    i create a sample about how to use jquery ajax ,please refer to the code below:

    <head runat="server">
        <title></title>
    
        <script src="scripts/jquery-1.10.2.js" type="text/javascript"></script>
        <link href="scripts/jquery-ui-1.10.4.custom.css" rel="stylesheet" />
        <script src="scripts/jquery-ui-1.10.4.custom.js" type="text/javascript"></script>
    <script type = "text/javascript">
    
    function SendResultsConfirmation(message) {
            $("#divDialog").html($("<h5>" + message + "</h5>"));
            $("#divDialog").dialog({
                width: '350',
                height: '175',
                modal: true,
                draggable: false,
                resizable: false,
                buttons: {
                    'Yes': function () {
                        
                        $.ajax({
                            type: "POST",
                            url: "CS.aspx/GetCurrentTime",
                            data: '{name: "' + "test"+ '" }',
                            contentType: "application/json; charset=utf-8",
                           dataType: "json",
                           success: OnSuccess,
                           failure: function(response) {
                   alert(response.d);
                     }
                         });
                            $(this).dialog('close');
                        },
                        'No': function () {
                            $(this).dialog('close');
                        }
                    }
    
                });
            };
    
    function OnSuccess(response) {
        alert(response.d);
    }
    </script> 
    </head>
    <body style = "font-family:Arial; font-size:10pt">
    <form id="form1" runat="server">
        <div id="divDialog" />
    <div>
          <a onclick="javascript:SendResultsConfirmation('xxx')">Hello</a>
    </div>
    
    </form>
    </body>

    code behind the page:

    [System.Web.Services.WebMethod]
    public static string GetCurrentTime(string name)
    {
        return "Hello " + name + Environment.NewLine + "The Current Time is: " 
            + DateTime.Now.ToString();
    }
    

    Hope it can help you.

    Best Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 28, 2014 9:55 AM

All replies

  • User1918509225 posted

    Hi Chithra_lyer,

    The problem is not in the jquery ui dialogbox,it is your  function have problem.

    i create a sample about how to use jquery ajax ,please refer to the code below:

    <head runat="server">
        <title></title>
    
        <script src="scripts/jquery-1.10.2.js" type="text/javascript"></script>
        <link href="scripts/jquery-ui-1.10.4.custom.css" rel="stylesheet" />
        <script src="scripts/jquery-ui-1.10.4.custom.js" type="text/javascript"></script>
    <script type = "text/javascript">
    
    function SendResultsConfirmation(message) {
            $("#divDialog").html($("<h5>" + message + "</h5>"));
            $("#divDialog").dialog({
                width: '350',
                height: '175',
                modal: true,
                draggable: false,
                resizable: false,
                buttons: {
                    'Yes': function () {
                        
                        $.ajax({
                            type: "POST",
                            url: "CS.aspx/GetCurrentTime",
                            data: '{name: "' + "test"+ '" }',
                            contentType: "application/json; charset=utf-8",
                           dataType: "json",
                           success: OnSuccess,
                           failure: function(response) {
                   alert(response.d);
                     }
                         });
                            $(this).dialog('close');
                        },
                        'No': function () {
                            $(this).dialog('close');
                        }
                    }
    
                });
            };
    
    function OnSuccess(response) {
        alert(response.d);
    }
    </script> 
    </head>
    <body style = "font-family:Arial; font-size:10pt">
    <form id="form1" runat="server">
        <div id="divDialog" />
    <div>
          <a onclick="javascript:SendResultsConfirmation('xxx')">Hello</a>
    </div>
    
    </form>
    </body>

    code behind the page:

    [System.Web.Services.WebMethod]
    public static string GetCurrentTime(string name)
    {
        return "Hello " + name + Environment.NewLine + "The Current Time is: " 
            + DateTime.Now.ToString();
    }
    

    Hope it can help you.

    Best Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 28, 2014 9:55 AM
  • User-16266343 posted

    Live saver answer. I spent 6 hours googling trying to troubleshoot the issue but this answer finally helped me resolve it.

    Saturday, May 7, 2016 2:11 AM