c# - Ajax post return error -
when post asmx web service, error returned:
could not create type 'myprojectname.autocompletewebservice'.
i tried answers in stackoverflow , many other sites, none 1 working in case.
jquery
$("#txtsearchkeyword").autocomplete({ source: function (request, response) { $.ajax({ url: "autocompletewebservice.asmx/indentifysearch", data: "{ 'keyword': '" + request.term + "','lang': 'en' }", datatype: "json", type: "post", contenttype: "application/json; charset=utf-8", datafilter: function (data) { return data; }, success: function (data) { $(currentelement).css({ "background": "rgb(255, 255, 255) none repeat scroll 0% 0% / auto padding-box border-box" }); response($.map(data.d, function (item) { return { value: item } })) }, error: function (xmlhttprequest, textstatus, errorthrown) { alert(textstatus); } }); }, open: function (event, ui) { //$(".ui-autocomplete").css("left", (parseint($(".ui-autocomplete").css("left").replace("px", "")) - 114).tostring() + "px"); }, minlength: 3, appendto: "#autocontainer" });
asmx
<%@ webservice language="c#" codebehind="autocompletewebservice.asmx.cs" class="royaltours.autocompletewebservice" %>
c#
[webservice(namespace = "http://tempuri.org/")] [webservicebinding(conformsto = wsiprofiles.basicprofile1_1)] [scriptservice] public class autocomp : system.web.services.webservice { [webmethod] public list<string> indentifysearch(string keyword) { string currentpageurl = httpcontext.current.request.url.absolutepath; list<package> olstpackage = null; olstpackage = new packagerepository().searchpackage(keyword); list<string> olstresult = null; if (olstpackage.count > 0) { olstresult = new list<string>(); (int indexcountry = 0; indexcountry < olstpackage.count; indexcountry++) { olstresult.add(olstpackage[indexcountry].keyword); if (olstpackage.count <= 0) { olstresult.removeat(indexcountry); } } } return olstresult; } }
i'd venture guess issue of class mismatch between .asmx
, .asmx.cs
files.
on top of .asmx
page, sure class
attribute matches class
@ top of .asmx.cs
page, so:
code-behind
public class myservice: system.web.services.webservice
front end
<%@ webservice language="c#" codebehind="myservice.asmx.cs" class="myproject.myservice" %>
it's common habit if using visual studio create new web service (which has default name of service1.asmx
), , rename myservice.asmx
. it's important note not update class references along filename, , can cause headache in event forget.
edit: went ahead , edited question clean code, realize had included markup page , code-behind.
just suspected, classes don't match. take look:
.asmx
class="royaltours.autocompletewebservice"
.asmx.cs
public class autocomp
Comments
Post a Comment