dazzling kumar
dazzling kumar

Reputation: 604

script not working in mvc4

im using script to bind my dropdown in my mvc project using web service and my webservice is present inside app_code but its not calling and error is called in my script

$(document).ready(function () {
$.ajax({
    type: "POST",
    contentType: "application/json,charset=utf-8",
    url: "/App_Code/WebService1.asmx.cs/loadcountry",
    data: "{}",
    datatype: "json",
    sucess: function (Result) {
        alert("s");
        $("#country").empty().append($("<option></option>").val("0").html("Select Country"));
        $("#state").empty().append($("<option></option>").val("0").html("Select State"));
        $each(Result.d, function () {
            $("#country").append($("<option></option>").val(this['Value']).html(this['Text']));
        });
    },
    error: function (Result) {
        alert("1");
    }
});
});

can anyone tell me where im going worng , thanks in advance

Upvotes: 0

Views: 83

Answers (5)

andrey.shedko
andrey.shedko

Reputation: 3238

  1. Change url to call WebService1.asmx, not WebService1.asmx.cs
  2. loadcountry. Does it has WebMethod attribute?
  3. According to the name loadcountry I suppose it should be GET method, not POST.

Upvotes: 0

ED-209
ED-209

Reputation: 4746

A bit of a guess but I reckon you need a 'GET' instead of a 'POST'. It looks to me like your webservice is simply providing a list of countries and doesn't accept any data posted to it.

You can test your webservice in a rest client like Chrome's Advanced Rest Client

Upvotes: 0

vfabre
vfabre

Reputation: 1408

I think that you have a few problems in your call, the first one is the metioned by Opec

And the other one is where you create the web service, here tell you why.

I recommend you that put your web services in the project root or in another folder. And then change your call to something like this:

url: "~/MyNewFolder/WebService1.asmx/loadcountry"

Upvotes: 0

Opec
Opec

Reputation: 85

Change the URL property by:

url: "~/App_Code/WebService1.asmx/loadcountry"

Edit:

And sucess by success (as Dethariel says in his answer).

Upvotes: 2

Dethariel
Dethariel

Reputation: 3624

Can this be a misspelling on the line sucess (should be success - double c)?

Upvotes: 1

Related Questions