2

I have made a WCF REST service which returns the response in JSON format and now I want to
call it from javascript.But when I try to call it I couldn't view any response. To make a javascript call I have written this:

<script src="Scripts/jquery-1.5.2.min.js" type="text/javascript">
</script>
<script language="javascript" type="text/javascript">
function Greeting() {
    $("#btnWCFREST").click(function() {
        $.ajax({
            url:"http://localhost:8732/Services/RoleService/json/Role/provider",
            type:"GET",
            dataType:"json",
            contentType:"application/json; charset=utf-8",
            successs: function(msg) {
                         alert(msg);
            },
            Error: function(msg) {
                      alert("Failed");
            }
        });
    }
}
</script>

How can I get the response. Where Am I going wrong?

2 Answers 2

1

You have a syntax error - you never close you click method call's parentheses:

        }); // end .ajax function
    } // // end .click function - should be });
} // end Greeting function declaration

Also, Error: should be error: (JavaScript is case-sensitive).

Sign up to request clarification or add additional context in comments.

2 Comments

I made ur above said changes and running the application.But when I check in developerTools Console window I got error like this: Failed to load resource: the server responded with a status of 405 (Method Not Allowed) localhost:8732/IServices/RoleService/json/Role/provider XMLHttpRequest cannot load http:/localhost:8732/IServices/RoleService/json/Role/provider Origin localhost:3098 is not allowed by Access-Control-Allow-Origin. How can I get rid of this error?
@cutiepie - you are serving your page and your web service off of different ports - that means that it is cross-domain as far as the browser is concerned. Either serve them both off the same port or have your web service send out a Access-Control-Allow-Origin header that allows access from the domain:port that your JavaScript is on.
1

You have an extra s in successs. Change it to success to get that function to work.

Also, you used an uppercase E in Error. I believe Javascript is case-sensitive, so you will probably need to change that to error (all lowercase).

The first parameter passed into the error function will be the jqXHR object and the second parameter is the error message. So if you actually want to get the error message (which you may not, since you aren't using it), then you will need to add another parameter to your error function.

Finally, as @SeanVieira pointed out, you are missing a closing parenthesis for your click function.

Comments

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.