I am a total noob to jQuery and Javascript..
need some help. I have an AJAX request hitting a php script. if the data is validated, the php will return some JSON. if there was an error, it returns an html string with the error texts (I can change this if needed to a json response but am happy with it as html for now…)
The problem I am having is how to identify the json response and code the subsequent if else statement in the JS to determine what to do next.
submitHandler: function(form) {
$.post( window.location, $("#checkoutCustomer").serialize(), function(data) {
// TODO: get this to respond to json response or html...
// need something here to detect presence of JSON in the post response
$('#checkoutCustomerResults').html(data); // the html response case
$(".continue_checkout_link").show(); // the json repsonse case
});
}
Ideally in the success scenario (JSON) the response should trigger the page to load a new URL in the browser, how do I do that also?
1 Answer