Quantcast
Viewing all articles
Browse latest Browse all 40

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');


Viewing all articles
Browse latest Browse all 40

Trending Articles