Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

542
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda