1

I have asp.net mvc4 project where I'm use an ajax query to get data from my server side

$.getJSON('/Administrator/GetStudentAppNumbers/', function(data) {
        //alert(data[0]);
        $.each(data, function (i, appNumber) {
            var program = $('"#' + appNumber + '"').html();
            var newProgram = $.trim(program).replace(/\s/g, " ");
            var shortText = $.trim(newProgram).substr(0, 40) + "...";
            $('"#' + appNumber + '"').html(shortText);
            $('"#' + appNumber + '"').click(function () {
                alert(newProgram);
            });
        });
    });

But when I try to invoke it in console, they return me an error:

Uncaught Error: Syntax error, unrecognized expression: "#UZ43"

And when I try to invoke it from alert(appNumber); they return me UZ43.

Have any ideas where I mistake?

3 Answers 3

2

The double quotes shouldn't be part of the value of the selector:

$('"#' + appNumber + '"')

Should be:

$('#' + appNumber)

With $("#UZ43"), the value of the selector is #UZ43.

With $('"#' + appNumber + '"'), the value is "#UZ43".

Sign up to request clarification or add additional context in comments.

Comments

0

Your selector is incorrect, so you are trying to call html() on a string; hence the error. Try this:

var program = $('#' + appNumber).html(); // note the removed double quotes (")

Comments

0

Try replacing

 $('"#' + appNumber + '"').html(shortText);

with

 $('#' + appNumber).html(shortText);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.