3

I have button and that jQuery script (to start the progress bar):

<script src="../_Files/JScripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="../_Files/JScripts/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script>

 var intervalID;
 $("#<%=this.Button1.ClientID%>").click(
            function() {

                intervalID = setInterval(updateProgress, 500);

                $.ajax({
                    type: "POST",
                    url: "CustomerImport.aspx/ExecuteImport",
                    data: "{}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: true,
                    success: function()
                    {
                        $("#progressbar").progressbar("value", 100);
                        clearInterval(intervalID);
                        $("#result").text('ok');
                    }
                });

                return false;
            }
        );

   function updateProgress() {

            $.ajax({
                type: "POST",
                url: "CustomerImport.aspx/GetProgress",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: true,
                success: function(msg) {
                    $("#result").text = msg.d;
                    var value = $("#progressbar").progressbar("option", "value");
                    if (value < 100) {
                        $("#progressbar").progressbar("value", msg.d);
                        $("#result").text(msg.d);
                    }
                    else {
                        clearInterval(intervalID);
                        window.location = window.location;
                    }
                }
            });
        }

the method:

    [System.Web.Services.WebMethod]
    public void ExecuteImport()
    {
        _Presenter.ExecuteImport();
    }

the problem is, that method is NOT being invoked. Why ?

When I replace the $.ajax for the e.g alert('ok'); the alert shows, so it works

3 Answers 3

3

Did you decorate your service class with the [ScriptService] attribute? Also try changing the data parameter to: data: { }. What does FireBug says about this? Is there a request being sent? If yes what does the server respond?

Also you have a mistake in your url (web services have the ASMX extension). You wrote:

CustomerImport.aspx/ExecuteImport

While it should be:

CustomerImport.asmx/ExecuteImport

Here's a complete working example that you may adapt to your needs:

Web service:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
[ScriptService]
public class CustomerImport : WebService
{
    [WebMethod]
    public void ExecuteImport()
    {
    }
}

Calling web page:

<%@ Page Language="C#" %>
<!doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test</title>
    <script type="text/javascript" src="scripts/jquery-1.4.1.js"></script>
    <script type="text/javascript">
        $(function () {
            $.ajax({
                type: 'POST',
                url: '/CustomerImport.asmx/ExecuteImport',
                data: { },
                success: function () {
                    alert('ok');
                }
            });
        });
    </script>
</head>
<body>

    <form runat="server">

    </form>

</body>
</html>
Sign up to request clarification or add additional context in comments.

5 Comments

FireBug says: Unknown web method GetProgress.Parameter name: methodName
I see that ExecuteImport and GetProgress method are unknown, firebug says
hm, but it is not a WebService, it is a aspx Page, is it makes a difference ?
Oh, ASPX page? Yes it makes a difference of course. Take a look at this link for an example: encosia.com/2008/05/29/… Your method has to be static in the ASPX page.
@DarinDimitrov who is responsible for CustomerImport.asmx/ExecuteImport to go to the page.asmx and execute the Excute function ? which module ? can you provide a link ?
1

Add in the error function to the ajax call... Hopefully you'll get some info back, as to why the call failed.

Are you using firebug? Watch the net tab.

 $.ajax({
    type: "POST",
    url: url,
    async: false,
    data: jsonEncodedParams,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (msg) {

    }, //success
    error: function (XMLHttpRequest, textStatus, errorThrown) {
      if (textStatus == "timeout") {
        alert('The request timed out, please resubmit');
      } //if
      else {
        alert(errorThrown);
      } //else
    } //error
  }); //ajax

Comments

1

Since your server-side endpoint is a "page method", it must be declared as static:

[System.Web.Services.WebMethod]
public static void ExecuteImport()
{
    _Presenter.ExecuteImport();
}

3 Comments

who is responsible for CustomerImport.asmx/ExecuteImport to go to the page.asmx and execute the Excute function ? which module ? can you provide a link ?
I don't understand the question. The specific ASP.NET HttpModule?
When yu request a URI in the internet , by its URL , it goes to a page , no to a method. So who is reponsible to Extract the page from the URL , and go to the Method which was also supplied in the URL. you are talking about a related info in your (excellent) site. I ask this question since I saw in you site the Jquery Ajax example with the static Asp.net function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.