jQuery/post():调用的URL不是我所期望的

jQuery/post(): the URL called is not what I expected

本文关键字:URL 期望 调用 post jQuery      更新时间:2023-09-26

我在http://myweb.localhost/miembros/id/1/mensajes有一个链接。当我单击该链接时,下面的代码被称为:

<script type="text/javascript">
   $('.switch_leido').click(function(){
     $.post('mensaje/cambiarEstadoLeido',
            {id:$(this).data('leido')},
            function(){
              alert("fasfsf");
            }
     );
   });

,我得到这个错误:

POST http://myweb.localhost/miembros/id/1/mensaje/cambiarEstadoLeido 404 (Not发现)

相反,我期望http://myweb.localhost/mensaje/cambiarEstadoLeido被调用,但没有…:S

我该怎么办?

哈维尔

您的路径是相对设置的。在前面使用"/"来引用网站的根目录

 $.post('/mensaje/cambiarEstadoLeido', ...

使用绝对路径?可以改成

 $.post('/mensaje/cambiarEstadoLeido',