Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

543
Views
Error: Syntax error, unrecognized expression When Return HTML

I want Delete row with jquery ajax , in my view i call js function for ajax controller/action

<a href="javascript:void(0);" onClick="markup2('@Url.Action("ChannelDelete", "MyInfo", new {area = ""})');" class="btn btn-lg btn-danger" style="margin-bottom: 15px;">Delete</a>
function markup2(e) {
  $(function() {
    $("#LoadPages").empty();
    $("#LoadPages").html('<div style="padding: 20px 15px"><div class="row"><div class="center-block col-md-1" style="float: none;"><img src="/Upload/pageLoader.gif" alt="loading..." /></div></div></div>');

    $.ajax({
      type: "POST",
      url: e
    }).done(function(data) {
      $("#LoadPages").load(data);
    });
    return false;
  });
}

The above function it's ok too , get url and send AJAX POST and get data; when return data (html) and Inserting into the $("#LoadPages") element (("#LoadPages").load(data))

get me an error:

Error: Syntax error, unrecognized expression:

<h2>my channels</h2>
    <table class="table">
        <tr>
            <th>
                channel name
            </th>
            <th>
                name
            </th>
            <th>
                UserSelectedChannelJoinDate
            </th>
            <th></th>
        </tr>
    </table>

I don't know why get error

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Firstly, you should really use unobtrusive event handlers instead of outdated on* event attributes.

Secondly, your issue is due to the use of load(). That method is intended to receive a URL to make an AJAX request which returns HTML, which is then set as the content of the specified element. However your code is giving a HTML string instead of a URL, hence the error.

To fix this, use html() instead of load():

<a href="#" data-action="@Url.Action("ChannelDelete", "MyInfo", new {area = "" })" class="btn btn-lg btn-danger">Delete</a>
$(function() {
  $('.btn').click(function(e) {
    e.preventDefault();

    $("#LoadPages").html('<div style="padding: 20px 15px"><div class="row"><div class="center-block col-md-1" style="float: none;"><img src="/Upload/pageLoader.gif" alt="loading..." /></div></div></div>');

    $.ajax({
      type: "POST",
      url: $(this).data('action')
    }).done(function(data) {
      $("#LoadPages").html(data);
    });
  });
});

I would also strongly suggest you use an external stylesheet instead of the style attribute in your HTML.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!