This is a quick tip sharing. Recently, I was stuck in a problem where I was making an AJAX call to get MVC partial as HTML in response.
Within this response, I made an attempt to find an element using $.find as following:
Within this response, I made an attempt to find an element using $.find as following:
.find threw an exception:
$.ajax({
url: theURL,
type: "POST",
success: function (data) {
var controls = $(data).find('#someTextBox'); }
});
Uncaught Error: Syntax error, unrecognized expression: <HTML response>
Issue was with enter keys and spaces in the response. Trimming data before calling find, resolved the issue.
var controls = $(data.trim()).find('#someTextBox');