0

我最近在我的网站上执行了一些 ajax 请求,但我还是初学者。

这是一个愚蠢的问题:如何在不等待任何响应的情况下向服务器发送(POST)数据?

在我在互联网上找到的所有示例中,ajax 调用用于重新加载页面的一部分。它工作得很好,但我的想法只是发送一个可以存储在数据库中的数据,例如无需等待任何响应。

我正在使用带有 MVC 模式的 Zend 框架。我试过类似的东西:

$.ajax({
    type: "POST",
    url:'/controller/action',
    data: { myDataToPost: aData },

        success:function(response){
        },
        failure:function(){
         alert('Could not save your entry');
        }
});  

如果我在控制器中定义一个动作,它工作正常,但我可以在萤火虫中看到控制器/动作页面上的 404 错误。肯定它不存在,因为我不想要任何回应......

非常感谢您的帮助!塞德里克。

4

1 回答 1

0

"Here is a stupid question: How to send (POST) a data to the server without waiting any response ?"

$.ajax({
     timeout: 1
});

Set the request timeout to 1 millisecond (zero doesn't work), thus giving the xmlHttpRequest 1 millisecond to complete (go to server, process request, return response, which is virtually impossible), otherwise mark it as timed out (failed).

于 2013-04-09T19:24:49.773 回答