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

119
Visualizações
Implement an Ajax call using the tags data-*

I'm trying to implement an Ajax call using the tags data-* as described at jquery-ajax-unobtrusive

I know that I can use a javascript function with $.ajax() but my purpose is to experiment with the tags data-ajax...

I tried this code in the cshtml file

<a class="btn btn-primary" data-ajax-url="/Home/AjaxSample" data-ajax="true" data-ajax-success="AjaxSuccess" data-ajax-failure="AjaxError" data-ajax-method="GET">Ajax</a>

// other code...

function AjaxSuccess() { alert('AjaxSuccess'); }
function AjaxError() { alert('AjaxError'); }

The browser shows the button of course, but nothing happens when I click it. I can't discover any error in the browser debugger. Nothing happens apparently.

Intellisense doesn't show the tags data-ajax and friends. Did I forget to include something?

Are there any complete working examples?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The answer from the comments (since no-one has added it):

<script src="~/lib/jquery-ajax-unobtrusive/jquery.unobtrusive-ajax.j‌​s"></script>
<!-- the ~ is to symbolize your project's wwwroot folder

Add the above to your master layout with all of your other scripts (_Layout.cshtml by default).

What this does is include the jQuery unobtrusive ajax file into all of your pages, so that the main script that does all the work is included.

Before doing this, make sure you have installed the package Microsoft.Jquery.Unobtrusive.Ajax

over 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