JQuery ajax json data function is always SyntaxError

JQuery using a very simple method to call GET and transfer data using a json program But the error was constantly running, then IE tells me "SyntaxError"

But I deleted the data parameter in order ...

Please help us see, in the end, the problem? Thank!

var url = "/demo/test.do";
$.ajax({
  url: url,
  method: "GET",
  dataType: "json",
  data: jQuery.parseJSON('[{"dispatch" : "add"}]'),
  success: function(data) {
      alert(data);
  },
  error: function(jqXHR, textStatus, errorThrown) {
      console.log(errorThrown);
  }
});
+4
source share
2 answers

IE and console.log have problems if ie8 doesn't have Dev tools.

+1
source

Give it a try. No need to try to parse JSON for input.

 var url = "/demo/test.do";
 $.ajax({
   url: url,
   method: "GET",
   dataType: "json",
   data: {
       "dispatch" : "add"
   },
  success: function(data) {
      alert(data);
  },
  error: function(jqXHR, textStatus, errorThrown) {
      console.log(errorThrown);
  }
});
0
source

Source: https://habr.com/ru/post/1583907/


All Articles