I am having trouble getting inside my Search WebMethod from my JQuery call. Maybe someone could help to point me in the right direction.
I also packed up everything
To solve a problem like this, the first thing to do is watch it in Firebug.
If you click the "Search" link and watch the POST request/response in Firebug's console, you'll see it's throwing a 500 server error: Invalid JSON Primitive.
The reason for that is because the key/value identifiers in your "data" JSON literal aren't quoted. Line 17 should be:
data: "{'text':'" + search + "'}",
Then, all will work as expected.
Note: The suggested data { test: search } will not work. If you provide jQuery with an actual JSON literal instead of a string, it will convert that into a key/value pair of test=search and POST that instead of the JSON. That will also cause an ASP.NET AJAX ScriptService or PageMethod to throw the Invalid JSON Primitive error.
You need to do the following (C#):
public static[WebMethod] attributeEnablePageMethods="true"And here is some sample javascript:
$().ready(function() {
$(yourDropDownList).change(LoadValues);
});
function LoadValues() {
PageMethods.YourMethod(arg1, CallSuccess, CallFailed);
}
function CallFailed(result) {
alert('AJAX Error:' + result.get_message());
}
function CallSuccess(result) {
//do whatever you need with the result
}