JSON Web Service returning data is null

Posted by Shashikant under Web Services, Remoting on 7/27/2016 | Points: 10 | Views : 187 | Status : [Member] | Replies : 1
I have a webservice that return JSON data but when I consume through ajax JQUERY it is returning error:

Error: TypeError: r is null
Source File: http://localhost:23967/WebServiceConsume.aspx
Line: 22

When I run webservice directly in browser as:

Result is :

Here is code:

Webservice Code:

using System;
[WebMethod(CacheDuration = 0, Description = "Country Name")]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetCountries()
DataTable dt = new DataTable("CountryTable");
string query = "SELECT * FROM Country";
OdbcCommand m_Command = new OdbcCommand(query, m_Connection.oCon);
m_Command.CommandType = CommandType.Text;
m_Command.Connection = m_Connection.oCon;
OdbcDataAdapter m_DataAdapter = new OdbcDataAdapter(m_Command);
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row;
foreach (DataRow dr in dt.Rows)
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
row.Add(col.ColumnName, dr[col]);
return serializer.Serialize(rows);
catch (Exception)

on my aspx page I am consuming this way:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebServiceConsume.aspx.cs" Inherits="WebServiceConsume" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

<script src="js/jquery.min.js"></script>
<script src="script/jquery-1.4.2.min.js"></script>
<script type="text/javascript">

$(document).ready(function () {

url: '',
data: "{}",
type: "POST",
cache: false,
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function (data) {
error: function (data) {
alert("Error"); //do something if there is an error
<form id="form1" runat="server">
<div id="response"></div>


Posted by: A2H on: 7/27/2016 [Member] [MVP] Bronze | Points: 25

This may not be related to the actual issue which you are facing. But I noticed that in the code provided you have two references of Jquery. Jquery code wont work if you have multiple references. Remove one of the references and try the operations.

Please mark my reply as answer if it helps to resolve your problem

Shashikant, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response