Running this one in VS2010 with Firefox as my default browser.
I have a very simple aspx page which connects to a webservice. The webservice is working correctly (which is a start).
First problem is that the button is not firing in the jQuery. If I wrap a simple alert() around the button and click the button, the alert pops up. I've put an alert in the jQuery and nothing is happening, so I'm presuming the event is not happening.
Second problem is interpretting the results. The webservice returns a ListItem. How do I tell the jQuery to return the result in resultsarray defined at the top of the JS?
Expand|Select|Wrap|Line Numbers
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>A quick and dirty hack</title>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
- <script type="text/javascript">
- var returnval = array(4);
- var server = "PB5\SQLEXPRESS";
- var db = "foobar\data";
- var cmds = "Select name from data where (age > 25 and hometown = 'frodsham');";
- $(document).ready(function () {
- $("#btnMore").click(function () {
- alert("In click function");
- $.ajax({
- type: "POST",
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- url: "WebService1.asmx\GetData",
- data: "{'server':" + server + ",'db':" + db + ",'cmds':" + cmds + "}",
- success: onSuccess,
- error: onError
- });
- });
- });
- function onSuccess(result) {
- alert("In onSuccess");
- $("#datalist").empty();
- var strings = result.d;
- for (var i = 0; i < strings.length; ++i)
- $("#datalist").append("<li>" + strings[i] + "</li>");
- }
- function onError(result) {
- alert(result.status + ": " + result.statusText);
- }
- </script>
- </head>
- <body>
- <form id = "form1" runat="server">
- <asp:ScriptManager ID="_scriptManager" runat="server">
- <Services>
- <asp:ServiceReference Path="WebService1.asmx" />
- </Services>
- </asp:ScriptManager>
- <div>
- <ul id="datalist"></ul>
- <br />
- <input type="button" id="btnMore" value="do it" />
- </div>
- </form>
- </body>
- </html>
Paul