jquery - Ajax call failing to consume the WCF restful service -
i have wcf restful
service exposes login method outside world defined below, validates given user credentials db (login table) & returns result in json
format
c# code:
[operationcontract] [webget(requestformat = webmessageformat.json, responseformat = webmessageformat.json, bodystyle = webmessagebodystyle.wrapped, uritemplate = "login/{suserid}/{password}")] list<parkinglotrestwcfservice> login(string suserid, string password);
definition of same
public list<parkinglotrestwcfservice> login(string suserid, string password) { parkinglotrestwcfservice login = null; list<parkinglotrestwcfservice> arrlist = new list<parkinglotrestwcfservice>(); string json = ""; seek { string _connectionstring = "data source=lm;initial catalog=parkinglotdb;integrated security=true"; string _sql1 = "select * [logindetails] empid = " + suserid + " , pwd = '" + password + "'"; sqlconnection _connection = new sqlconnection(_connectionstring); sqlcommand _command = new sqlcommand(_sql1, _connection); _connection.open(); sqldatareader reader = _command.executereader(); if (reader.hasrows) { reader.close(); string _sql2 = "exec [dbo].[loginverify]"; sqlcommand _command2 = new sqlcommand(_sql2, _connection); sqldatareader reader2 = _command2.executereader(); reader2.read(); login = new parkinglotrestwcfservice(); login.status = "valid"; login.empid = reader2["empid"].tostring(); login.empname = reader2["name"].tostring(); login.secflag = reader2["secflag"].tostring(); arrlist.add(login); reader2.close(); //javascriptserializer ser = new javascriptserializer(); //json = ser.serialize(arrlist.toarray()); weboperationcontext.current.outgoingresponse.contenttype = "application/json; charset=utf-8"; weboperationcontext.current.outgoingresponse.headers.add("access-control-allow-origin", "*"); weboperationcontext.current.outgoingresponse.headers.add("access-control-allow-methods", "get"); weboperationcontext.current.outgoingresponse.headers.add("access-control-allow-headers", "content-type, accept"); } else { reader.close(); login.status = "invalid"; login.empid = string.empty; login.empname = string.empty; login.secflag = string.empty; arrlist.add(login); } _connection.close(); } grab (exception ex) { throw ex; } homecoming arrlist; }
jquery ajax code:
$('#signin').on('click',function(){ var userid=$('#userid').val(); var pass=$('#password').val(); var surl='http://localhost/parkinglotrestwcfservice.svc/login/'+userid+'/'+pass; $.ajax({ url: surl, type:"get", contenttype: 'application/json; charset=utf-8', datatype:"jsonp", jsonp:'jsonp', crossdomain:true, success: function (data, textstatus, jqxhr) { //process json response alert("success:"+retdata); }, error:function (result, sts, err) { alert("inside error block"); alert(err+":"+sts+":"+result); }, complete: function (jqxhr, textstatus) { alert("completed"); } }); });
so problem whenever create ajax phone call command goes error block, though can see actual json
info in response
section under net
tab in firebug console.the error message within error block alerted error: jquery111108245764932074613_1403187289975 not called:parsererror:[object object].
i firebug console error message
syntaxerror: missing ; before statement {"loginresult":[{"empid":"300","empname":"user1","logintime":null,"logo -------------^
here json response returned wcf service
json response: {"loginresult":[{"empid":"300","empname":"user1","logintime":null,"logouttime":null,"secflag":"a","slotno":null,"status":"valid","vechicleno":null,"vechicletype":null}]}
note:
if nail url passed jquery straight browser returning me json info without error, same not working jquery ajax call i verifiedjson
response @ http://jsonlint.com/ , valid json any quick help much appreciated guys :)
web.config
<configuration> <system.web> <compilation debug="true" targetframework="4.0"> <authentication mode="none"> </authentication></compilation></system.web> <system.webserver> <modules runallmanagedmodulesforallrequests="true"> </modules></system.webserver> <system.servicemodel> <servicehostingenvironment **aspnetcompatibilityenabled**="true"> <standardendpoints> <webscriptendpoint> <standardendpoint **crossdomainscriptaccessenabled**="true" name=""> </standardendpoint></webscriptendpoint> </standardendpoints> </servicehostingenvironment></system.servicemodel> </configuration>
jquery ajax json wcf restful-url
No comments:
Post a Comment