Calling WebServices Jquery
<p>I have a simple ajax request that I am trying to call a web service I created. The web service code is never being executed. I got this code sample from the net and I think maybe I am calling the url wrong in the jquery i dunno?</p>

<p>here is the jquery</p>

<pre><code>&lt;script type="text/javascript"&gt;
    $(document).ready(function() { 

    alert("Hi");
        $("#btnTitleQuery").bind("click", function() {
            $("#query_results").empty();
            $("#query_results").append('&lt;table id="ResultsTable" class="BooksTable"&gt;&lt;tr&gt;&lt;th&gt;BookNum&lt;/th&gt;&lt;th&gt;Title&lt;/th&gt;&lt;th&gt;Author&lt;/th&gt;&lt;/tr&gt;');
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "BookServices.asmx/GetBooksByTitle",
                data: '{ strTitle: "' + $("#txtTitle").val() + '" }',
                dataType: "json",
                success: function(msg) {
                    var c = eval(msg.d);
                    for (var i in c) {
                        $("#ResultsTable tr:last").after("&lt;tr&gt;&lt;td&gt;" + c[i][0] + "&lt;/td&gt;&lt;td&gt;" + c[i][1] + "&lt;/td&gt;&lt;td&gt;" + c[i][2] + "&lt;/td&gt;&lt;/tr&gt;");
                    }
                }
            });
        })
        $("#btnAuthorQuery").bind("click", function() {
            $("#query_results").empty();
            $("#query_results").append('&lt;table id="ResultsTable" class="BooksTable"&gt;&lt;tr&gt;&lt;th&gt;BookNum&lt;/th&gt;&lt;th&gt;Title&lt;/th&gt;&lt;th&gt;Author&lt;/th&gt;&lt;/tr&gt;');
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "BookServices.asmx/GetBooksByAuthor",
                data: '{ strAuthor: "' + $("#txtAuthor").val() + '" }',
                dataType: "json",
                success: function(msg) {
                    var c = eval(msg.d);
                    for (var i in c) {
                        $("#ResultsTable tr:last").after("&lt;tr&gt;&lt;td&gt;" + c[i][0] + "&lt;/td&gt;&lt;td&gt;" + c[i][1] + "&lt;/td&gt;&lt;td&gt;" + c[i][2] + "&lt;/td&gt;&lt;/tr&gt;");
                    }
                }
            });
        })
    }); 
&lt;/script&gt;
</code></pre>

<p>The web service is in my root directory.</p>

<pre><code>using System;

 using System.Web;

 using System.Collections;

 using System.Web.Services;

using System.Web.Services.Protocols;

 using System.Data;

  using System.Data.Odbc;

   using System.Web.Script.Serialization;

 using System.Web.Script.Services;

namespace TryWillJSON
{

 [WebService(Description = "Web services to query the book database.", Namespace = "http://www.williamsportwebdeveloper.com/")]

  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

   [ScriptService]

 public class BookServices : System.Web.Services.WebService {



       public BookServices () {



        //Uncomment the following line if using designed components 

         //InitializeComponent(); 

     }



     [WebMethod(Description = "Gets the books matching part of a title.")]

    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]

     public string GetBooksByTitle(string strTitle) {

        OdbcConnection objConnection = new OdbcConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Books"].ConnectionString);

         OdbcCommand objCommand = new OdbcCommand("SELECT * FROM reading WHERE Title LIKE '%" + strTitle + "%' ORDER BY BookNum;", objConnection);

         DataSet objDataSet = new DataSet();

         OdbcDataAdapter objDataAdapter = new OdbcDataAdapter(objCommand);

         objDataAdapter.Fill(objDataSet, "reading");

           objConnection.Close();



         // Create a multidimensional jagged array

        string[][] JaggedArray = new string[objDataSet.Tables[0].Rows.Count][];

        int i = 0;

         foreach (DataRow rs in objDataSet.Tables[0].Rows)

        {

            JaggedArray[i] = new string[] { rs["BookNum"].ToString(), rs["Title"].ToString(), rs["Author"].ToString() };

             i = i + 1;

          }



        // Return JSON data

         JavaScriptSerializer js = new JavaScriptSerializer();

      string strJSON = js.Serialize(JaggedArray);

       return strJSON;

      }



     [WebMethod(Description = "Gets the books matching part of an author's name.")]

   [ScriptMethod(ResponseFormat = ResponseFormat.Json)]

    public string GetBooksByAuthor(string strAuthor)

       {

         OdbcConnection objConnection = new OdbcConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Books"].ConnectionString);

         OdbcCommand objCommand = new OdbcCommand("SELECT * FROM reading WHERE Author LIKE '%" + strAuthor + "%' ORDER BY BookNum;", objConnection);

         DataSet objDataSet = new DataSet();

        OdbcDataAdapter objDataAdapter = new OdbcDataAdapter(objCommand);

        objDataAdapter.Fill(objDataSet, "reading");

        objConnection.Close();



          // Create a multidimensional jagged array

         string[][] JaggedArray = new string[objDataSet.Tables[0].Rows.Count][];

        int i = 0;

        foreach (DataRow rs in objDataSet.Tables[0].Rows)

      {
             JaggedArray[i] = new string[] { rs["BookNum"].ToString(), rs["Title"].ToString(), rs["Author"].ToString() };

             i = i + 1;

        }



          // Return JSON data

        JavaScriptSerializer js = new JavaScriptSerializer();

         string strJSON = js.Serialize(JaggedArray);

         return strJSON;

     }



   }
}
</code></pre>

<p>I can see the alert hits, but in firebug when I check whats in the "msg" parameter of the jquery function firebug tells me this "ReferenceError: msg is not defined"</p>

<p>Here is where I am getting the code: 
williamsportwebdeveloper.com/cgi/wp/?p=494 </p>

<p>If anyone has time can you see if you can set it up correctly in visual studio</p>

<p>Here is a fiddle I setup as well for what its worth
<a href="http://jsfiddle.net/npl77/U33XS/" rel="nofollow">http://jsfiddle.net/npl77/U33XS/</a></p>
