How to convert simple form submit to ajax call;

ajax, html, javascript

Solution

I don't know how but this one runs well,

    var algorithm = document.forms["algoForm"]["algorithm"].value;
    var input = document.forms["algoForm"]["input"].value;

    $.post('run.do', {  
            algorithm  : algorithm,
            input      : input
        }, function(data) {                  
            alert(data);
        }
    );

Problem

I have a form with input field which can be accessed like ``` var algorithm = document.forms["algoForm"]["algorithm"].value; var input = document.forms["algoForm"]["input"].value; ``` and earlier call was ``` document.forms["algoForm"].submit(); ``` and form was ``` <form name="algoForm" method="post" action="run.do"> ``` It all run fine Now I wanted convert it to the ajax call so that I can use the returned data from java code on the same page. So I used soemthing like ``` var algorithm = document.forms["algoForm"]["algorithm"].value; var input = document.forms["algoForm"]["input"].value; var data = 'algorithm = ' + algorithm + '&input = ' + input; $.ajax( { url: "run.do", type: "POST", data: data, success: onSuccess(tableData) { //line 75 alert(tableData); } } ); ``` However the above code doesn't run. Please help me make it run

Original source