I wrote a search program using lucene.net. The search method returns a string containing an html table with the search results. This part works, but I wanted the ability to submit the search without reloading the entire page... So I searched and found that this could be done using AJAX. For whatever reason I cannot get it to work.
I'm not throwing an error. The contents of "Search.aspx" get returned, but it seems like the Submit Method never executes.
Search.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Search.aspx.cs" Inherits="Search" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<script type="text/javascript">
$(function () {
$(".sBM").click(function () {
dataString = "valve"
$.ajax({
type: "POST",
url: "Search.aspx/Submit",
//data: dataString,
data: dataString,
contentType: "application/html; charset=utf-8",
dataType: "html",
success: function (msg) {
$("#searchResults").text(msg);
alert(msg);
},
error: function (xhr, ErrorText, thrownError) {
$("#searchResults").text("Error" + xhr.status);
}
});
return false;
});
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<div class="sHead">
<div id="search_form" class="sSBM">
<form name="search" action="">
<fieldset>
<label for="name" id="rpe_label">RPE Search</label>
<input type="text" name="query" value="" class="sTM" />
<input type="submit" name="submit" class="sBM" id="submit_btn" value="" />
</fieldset>
</form>
</div>
</div>
<div id="searchResults" ></div>
</asp:Content>
CodeFile:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
public partial class Search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string Submit(string query)
{
SearchDoc seek = new SearchDoc();
return seek.Search("valve");
}
}