Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>you are not defining <code>data</code> in your success callback function definition </p> <pre><code> $.ajax({ type: "GET", url: "calculator.jsp", data: str, cache:false, success: function(data) { //you need data defined </code></pre> <p>Depending on what data is being returned you might need to specify the return type by using <code>dataType</code> option</p> <pre><code> $.ajax({ type: "GET", url: "calculator.jsp", data: str, cache:false, dataType:"json", success: function(data) { //access properties through data var msg = data.val1 + " + " + data.val2 + " = " + data.sum + '\n'; </code></pre> <p><strong>Additional Edit</strong></p> <p>Also it looks like you have the click event attached to the submit button which is probably causing the script to submit to itself or whatever page you have set in the <code>action</code> attribute, you need to have it cancel the default action by using <code>preventDefault</code></p> <pre><code>$(".button").click(function(e) { //e will hold the event object e.preventDefault() //prevents the default action of the event, //in this case the form submission var str = $("form").serialize(); </code></pre> <p>you may also be getting a parse error, you can set an error callback as well</p> <pre><code>$.ajax({ type: "GET", url: "calculator.jsp", data: str, cache:false, dataType:"json", success: function(data) { var msg = data.val1 + " + " + data.val2 + " = " + data.sum; alert(msg); }, error:function(xhr,errormsg) { alert(errormsg); } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload