when i run below code.
it makes error and alert "fail error:StntaxError: Unexpected token < in JSON at position 0 data:undefined"
what is the problem ??
$("#a").click(function () {
st_dt = $("#st_dt").val();
end_dt = $("#end_dt").val();
lot_cd = $("#lot_cd").val();
var obj = { st_dt: st_dt, end_dt: end_dt, lot_cd: lot_cd };
var json_1 = JSON.stringify(obj);
$.ajax({
type: "POST",
url: '{{ url_for("get_operid") }}',
data: json_1,
dataType: "JSON",
success: function (data) {
alert("Successn" + data);
},
error: function (request, status, error, data) {
alert("failn" + "error:" + error + "n data:" + data);
}
});
});
2
Answers
Looking at the code it looks like a Laravel API request using Blade Template or the Function url_for is in Flask… In either case
i.e. The API request is returning a login page or some HTML page…
To check the response you can open the Chrome Devtools in the Network tab check the response of the API…
what you can try is :
Then See in browser console what is your object and if the JSON converting your object properly.
If that is ok , Your request should be done currectly. And try to see what are the data you getting as response with:
You will find the error. I hope.