Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

541
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda