In a single request
$.ajax ({
Cache:true,
Type: "POST",
URL: "Getdatalist.action",
Async:false,
Error:function (Request) {
Alert ("Connection error");
},
Success:function (data) {
var jsondata = eval (data);
$ ("#weather"). Val (Jsondata.weatherinfo);
}
});
Error: syntaxerror:missing; Before statement
Very angry obviously no less, but the hint of error, search on the internet a lot of answers are the special symbols plus escape character method but not for my this
It was later discovered that the datatype needed to be specified: ' JSON ' can be perfectly solved
$.ajax ({
Cache:true,
Type: "POST",
URL: "Getdatalist.action",
Async:false,
DataType: ' JSON ',
Error:function (Request) {
Alert ("Connection error");
},
Success:function (data) {
Jsondata = eval (data);
$ ("#weather"). Val (Jsondata.weatherinfo);
}
});
Additional: In JS to get the JSON result passed in the background, generally using var res=eval (${data}) instead of using Var res= ' ${data} '
Ajax request background does not error but always executes the error function method
Cause this
1 You may have used asynchronous commit (Async=true)
2 You specified the datatype in the AJAX request, but the parameters you sent back were not passed in the type you specified.