473,320 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why isn't ajax button not firing and interpreting the return value?

Paul Johnson
Hi,

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
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head runat="server">
  3.     <title>A quick and dirty hack</title>
  4.     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
  5.     <script type="text/javascript">
  6.  
  7.         var returnval = array(4);
  8.         var server = "PB5\SQLEXPRESS";
  9.         var db = "foobar\data";
  10.         var cmds = "Select name from data where (age > 25 and hometown = 'frodsham');";
  11.  
  12.         $(document).ready(function () {
  13.             $("#btnMore").click(function () {
  14.             alert("In click function");
  15.                 $.ajax({
  16.                     type: "POST",
  17.                     contentType: "application/json; charset=utf-8",
  18.                     dataType: "json",
  19.                     url: "WebService1.asmx\GetData",
  20.                     data: "{'server':" + server + ",'db':" + db + ",'cmds':" + cmds + "}",
  21.                     success: onSuccess,
  22.                     error: onError
  23.                 });
  24.             });
  25.         });
  26.  
  27.         function onSuccess(result) {
  28.             alert("In onSuccess");
  29.             $("#datalist").empty();
  30.             var strings = result.d;
  31.             for (var i = 0; i < strings.length; ++i)
  32.                 $("#datalist").append("<li>" + strings[i] + "</li>");
  33.         }
  34.  
  35.         function onError(result) {
  36.             alert(result.status + ": " + result.statusText);
  37.         }
  38.  
  39.     </script>
  40. </head>
  41. <body>
  42. <form id = "form1" runat="server">
  43. <asp:ScriptManager ID="_scriptManager" runat="server">
  44.   <Services>
  45.     <asp:ServiceReference Path="WebService1.asmx" />
  46.   </Services>
  47. </asp:ScriptManager>
  48.  
  49. <div>
  50. <ul id="datalist"></ul>
  51. <br />
  52. <input type="button" id="btnMore" value="do it" />
  53. </div>
  54.  
  55. </form>
  56. </body>
  57. </html>
  58.  
Thanks

Paul
Nov 2 '10 #1
1 1713
acoder
16,027 Expert Mod 8TB
Check the jQuery.ajax() function options. You probably want to set processData to false.

For the second problem, you expect json, so parse the response using a JSON parser. Make sure the webservice is returning valid JSON.
Nov 4 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: sindre | last post by:
Hi, Some place I use links to submit forms instead of a submit button. The way I have done this is: <a href="javascript:document.getElementById('<?php print "delete$i"...
2
by: steve bull | last post by:
I have built what I think should be a dialog box. It contains 4 tabbed panes for generating a range of colors. Each tabbed pane consists of a panel with all the widgets on them including the OK and...
1
by: DotNetJunkies User | last post by:
I want to include javascript confirm inside the Button_Click even procedure and contine the process based on the user selection. The real problem is how to assign javascript confirm return value to...
3
by: Venkat Chellam | last post by:
HI all, I am finding a very peculiar problem. I have two pages. From the first page on button click i have javascript function which it turn opens modal dialog box with second page as a...
5
by: siaj | last post by:
Hello, I have a javascript function for a validation in the HTML page of the asp.Net page.. I call this function in a Savebutton click When the validation fails No postback should happen ( ie...
8
by: bdobby | last post by:
Hi. I am relatively new to js, but I did think I was starting to get the hang of it. Then this happened... I have a form with an onsubmit event handler: <form id="uploadForm" method="post"...
9
by: Water Cooler v2 | last post by:
Is it necessary to return a value from the event handlers? For instance, what does the return value in the following code signify? What will be its impact if it returned otherwise (true)? <a...
3
by: ashishc | last post by:
Hi I want to know how can I get the return value from a function into a variable onClick event of a selection of radio button. Let me explain in detail, I have 3 radio buttons and if i select any...
6
by: SAL | last post by:
hello, I'm using a radiobuttonlist in an updatepanel in an item template in a Gridview control. I'm populating the radiobuttonlist in the RowDataBound event. I have the control toolkit registered...
3
by: techbytes | last post by:
I have a form in jsp that inserts data into the table,after inserting successful message and error message should be shown in the design page thr ajax. I have the error messge value in my jsp...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.