Home show values entered in form as a table before getting submitted

# show values entered in form as a table before getting submitted

user_777
1#
user_777 Published in 2018-02-14 05:17:15Z
 First, I do not have much talent in ajax so please consider that while answering. Here I want to get all the values which I inserted into the form in a table before getting submitted but unfortunately am not getting the results I want. So far I have done this. Please have a look.   Here I want to pass the values of form_data in to the table I had written and how can we pass that and did it compulsory to use the url in ajax while using this am getting an error like error: parsererror: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data. Here is my controller public function ajax_data() { $array = array("agent_name" => "admin","number"=>"785","type"=>"super","quantity"=>"10");$data['json'] = $array; echo json_encode($data); } 
 The Ajax post will call the controller method for post values. The ajax code usually correct but you have not defined url.  url: '',  Firstly define a method (ex: HomeController) then set ajax url parameter like url: '@Url.Action("Save","Home")' or url: 'Save/Home'  [HttpPost] public JsonResult Save(string agent_name, string type , int number,int quantity) { // return json }  Note : The data types you send from the form with the method types must be the same.
 Well, just to give you some hints to work on: The Ajax call could look like this: $.ajax({ type: 'POST', url: 'echodata.php', data: form_data, dataType:"json", success: function(data){$('#table').append('
' // + more columns ... +'');} );  The php script should really be something that processes the incoming information (passed as the \$_POST array) into some other data that will ultimately be echoed as JSON string. This is just a trivial version of echodata.php for testing:   EDIT: While you have fixed your URL attribute and have added a "controller" on the server your Ajax success function still expects something it will not get. Your PHP script delivers a JSON string that will be parsed into as a JavaScript object and not an array. The object will not have the length property your success function tries to use. Instead you should be looking for the json property. So, there is no point for the for loop, instead you can use data.json.agent_name, data.json.number and data.json.type (etc.) properties directly. Your current .append() also only adds a static string to your table. This should of course be changed to use the freshly received values.