jQWidgets Forums
jQuery UI Widgets › Forums › Grid › CSV to JSOn using javascript
This topic contains 4 replies, has 2 voices, and was last updated by purnima 9 years, 10 months ago.
-
Author
-
Hi Team,
I have this grid data and i put it all together in a variable data. as shown below.var data= \$("#jqxgrid").jqxGrid('exportdata', 'csv');
If i do console.log(data), this is wat i get.
"Order","Id","Comment" "1.00","345.00","Do this" "2.00","475.00","Dont do this"
Can you please let me know a way i can convert this csv data to json data before sending it to backend via ajax. If the data is json, my further server side script handling becomes easy. pls help !!!!
Hi purnima,
Simply export the data to json.
var data = $("#jqxgrid").jqxGrid('exportdata', 'json');
Best Regards,
Ivailo IvanovjQWidgets Team
http://www.jqwidgets.comHi,
ok, i hav given json data as my data to ajax for transfer. But i get a alert(‘Error’); at the output. What could possibly be wrong with the below script. It should show me alert(‘Success’)…. right ?? when i checked the network tab, status 200 gets displayed.
This is the script….
<script> \$(document).ready(function() { \$("#savefile").click(function() { var data = \$("#jqxgrid").jqxGrid('exportdata', 'json'); console.log(data); \$.ajax({ type: "POST", url: "http://apmqa.mcm.com/cgi-bin/test/web_editor.pl?action=SaveJsonToCSV1", dataType: "json", data:data, success: function (data) { alert('Success'); }, error: function (data) { alert('Error'); } }); }); }); </script>
This is the output from the network tab….
Remote Address:167.113.9.236:80 Request URL:http://apmqa.mcm.com/cgi-bin/test/web_editor.pl?action=SaveJsonToCSV1 Request Method:POST Status Code:200 OK Response Headers view source Connection:Keep-Alive Content-Type:text/html; charset=ISO-8859-1 Date:Fri, 17 Jul 2015 20:54:16 GMT Keep-Alive:timeout=5, max=98 Server:Apache/2.2.25 (Win32) Transfer-Encoding:chunked Request Headers view source Accept:application/json, text/javascript, */*; q=0.01 Accept-Encoding:gzip, deflate Accept-Language:en-US,en;q=0.8 Connection:keep-alive Content-Length:7041 Content-Type:application/x-www-form-urlencoded; charset=UTF-8 Host:apmqa.mcm.com Origin:http://apmqa.mcm.com Referer:http://apmqa.mcm.com/cgi-bin/test/web_editor.pl User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36 X-Requested-With:XMLHttpRequest
Since i am getting status code:200 ok…. does it mean that my client is able to send data properly. The server side script is not able to handle the recieved data… is it like tat ??
I changed below code
dataType: "json",
I instead wrote the below comment and it worked.
contentType:"application/json",
-
AuthorPosts
You must be logged in to reply to this topic.