JQuery unrecognized expression in parsing MVC Partial

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:


  
$.ajax({
url: theURL,
type: "POST",
success: function (data) {
var controls = $(data).find('#someTextBox'); }
});
.find threw an exception:
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');

Comments

Popular posts from this blog

How to construct a B+ tree with example

How to show only month and year fields in android Date-picker?

Visitor Counter Script Using PHP