Sorry, I'm new to JS and don't know how to test this IF condition.
If the JSON response has content = false, then this popupSubmit function must be called.
Please assist in checking and letting me know where the error is if the condition is written.
Thanks
{
"id": "4974635f-514e-4d26-8170-ae77c984e8ab",
"content": "true",
"status": "SUCCESS",
"redirect": null
}
var checkID = $('#id-no').val();
var getDomainName = window.location.origin;
$.ajax({
url: getDomainName '/.rest/stripe/v1/checkID?id=' checkID,
type: 'GET',
dataType: 'json',
success: function success(response) {
//response = JSON.parse(response);
$.each(response, function (i, v) {
console.log(i.content);
if (i.content == 'false') {
popupSubmit();
}
});
}
});
CodePudding user response:
if(response.content == 'false'){
popupSubmit();
}
CodePudding user response:
Firstly, you are using incorrect syntax in the ajax
call. There shouldn't be any curly brackets. Secondly, you should check the content of values in the response, not indexes. Here's the correct code:
$.ajax(
url: getDomainName '/.rest/stripe/v1/checkID?id=' checkID,
type: 'GET',
dataType: 'json',
success: function (response) {
// response = JSON.parse(response);
$.each(response, function (i, v) {
console.log(i.content);
if (i.content == 'false') {
popupSubmit();
}
});
}
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>