0

Looks like it just doesnt want to work...

@ Webservice:

<ScriptMethod(UseHttpGet:=False, ResponseFormat:=ResponseFormat.Json), WebMethod()> _
    Public Function LoginDB(ByVal user As String, ByVal pass As String) As String
        global.user = user
        global.pass = pass
        If (<<lots of code to check if user is valid>>) Then
            Return "1"
        Else
            Return "0"
        End If
    End Function

The webservice DOES work, if the user is valid, returns 1 otherwise 0. But I always get it as XML

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">"0"</string>

@Jquery:

$.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "Services/Autenticacao.asmx/LoginDB",
                data: "{'user':'ale','pass':'123'}",
                dataType: "json",
                success: function(data) {
                    alert(data);
                },
.....

Anyone?

ale
  • 171
  • 1
  • 2
  • 8

2 Answers2

2

You need to post your jQuery, but are you using the getJson jQuery method? If not you need to explicitly set the correct data type:

$.ajax({
  type: "POST",
  contentType: "application/json; charset=utf-8",
  url: "WebService.asmx/WebMethodName",
  data: "{}",
  dataType: "json"
});

Or use the getJSON method:

$.getJSON('WebService.asmx/WebMethodName', function(data) {
    //Do something with JSON response (data)
});
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dustin Laine
  • 37,935
  • 10
  • 86
  • 125
  • jQuery always returns "null" $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "Services/Autenticacao.asmx/LoginDB", data: "{'user':'ale','pass':'test'}", dataType: "json", success: function(data) { alert(data); }, All i get is "null" – ale Jul 04 '10 at 22:56
  • Have you set a breakpoint on the web method? If so what is the result before it is returned? – Dustin Laine Jul 04 '10 at 23:10
  • What do you mean? The webservice works fine, i just have no clue why its returning XML instead JSON, it's most likely ASP.NET problem...I just dont understand why the hell I'm getting a XML. all jQ returns me is "NULL" – ale Jul 04 '10 at 23:17
0

If you want your webservice to return JSON

asked and answered... How to return JSON from a 2.0 asmx web service

Community
  • 1
  • 1
matt-dot-net
  • 4,204
  • 21
  • 24