Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is a cleaner / better way of parsing data received by an ajax success function?
    text
    copied!<p>I am using an ajax function to receive data. Based on that data, if results are not found I receive a string "No matches found" with some html formatting. If there are results, data is formatted into a table and a "Div" section underneath this section is hidden.</p> <p>Now the issue I am having is, when I find no results, i do not want this "Div" table to disappear.But to check if there are no results, I would have to compare the whole string received by the searchCustomer.php (which is very large).</p> <p>Is there an easier way of doing this?</p> <p>My ajax call:</p> <pre><code>$('#search').click(function(e){ $.ajax({ type : 'GET', url : 'searchCustomer.php', dataType :'html', data:{ lastName : $('#search_LN').val(), firstName : $('#search_FN').val(), phone : $('#search_PN').val() }, success : function(data){ if (data.error == true){ alert("there was an error in the post layer"); } else { $('#searchResults').html(data); if (data.text == '&lt;br&gt;&lt;font color='red'&gt;No matches found&lt;/font&gt;'){ }else{ var ele = document.getElementById("NewCustomerDiv"); ele.style.display = "none"; } } } }); return false; }); </code></pre> <p>Running fire-bug, The actual data received from searchCustomer.php is:</p> <pre><code>&lt;style type="text/css"&gt; a.resultBookButton { color: black; padding: 1px; border: 2px outset lightgrey; background: #008800; /* Mozilla: */ background: -moz-linear-gradient(top, lightgrey, #FFFFFF); /* Chrome, Safari:*/ background: -webkit-gradient(linear, left top, left bottom, from(lightgrey), to(#FFFFFF)); text-decoration: none; } a:active { border-style: inset; } &lt;/style&gt; &lt;br&gt;&lt;font color='red'&gt;No matches found&lt;/font&gt; </code></pre> <p>I just want to check for "No matches found" or if there is a better way of finding no results.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload