jquery ajax how to know the return data is xml or html? -
how can know/ test return data jquery ajax xml, html or plain text?
for instance, have these 2 types of data want handle.
xml,
<?xml version="1.0"?> <xml><response><error elementid="accept_terms_conditions" message="field 'agree terms & conditions' needs filled."/></response></xml>
html,
<form action="http://xxx/booking.php" method="post" enctype="multipart/form-data" class="item-form border-top-bottom"> ... </form>
jquery,
$(".button-submit").click(function(){ var form = $(this).closest("form"); var url = form.attr("action"); // load article object. $.ajax({ type: "post", //datatype: "html", url: url, data:form.serialize(), context:$(".holder-form-book-online"), async: false, beforesend: function() { // }, success: function (returndata) { if(returndata.isxml) alert("xml"); if(returndata.ishtml) alert("html"); } }).fail(function() { alert("error"); }); return false; });
so,
if(returndata.isxml) alert("xml"); if(returndata.ishtml) alert("html");
is possible?
var conttype = returndata.getresponseheader ("content-type"); if(conttype == "") { // take here... }
Comments
Post a Comment