简体   繁体   English

如果我的函数未返回任何内容,是否有必要在Ajax调用中成功作为参数?

[英]Is is necessary to have success as a parameter in Ajax call if my function is not returning anything?

I am doing an ajax call on the click of an image. 我正在点击图片进行ajax调用。 The image has an href tag so on its click, it opens some page in other tab. 该图像具有href标记,因此单击它会在其他选项卡中打开某些页面。 The purpose of doing ajax call here is I'm just saving the user clicks on the image for telemetry purpose in database table. 在这里进行ajax调用的目的是,我只是将用户点击图像保存在数据库表中以进行遥测。 Hence I'm not returning anything from ajax call. 因此,我没有从ajax调用返回任何东西。 So is it necessary to have "success" as a parameter in my ajax call? 那么在我的Ajax调用中是否有必要将“成功”作为参数?

      var url = '/Home/ClicksCount'
      $.ajax({
        url: url,
        type: 'POST',
        data: { imageclick : 1},
        success: function (data)
        { }
    });
}

This function is called on the click of that image. 单击该图像时将调用此函数。 So is success parameter necessary here? 那么这里成功参数是否必要? Is it okay if I remove that? 如果我删除它可以吗? I don't want to show an error as of now if the ajax call fails. 如果ajax调用失败,我现在不希望显示错误。

Success is an option in ajax call. 成功是ajax调用中的一个选项。 If you don't want it you can skip it, But using it is a better choice for knowing the ajax call status. 如果您不希望它可以跳过它,但是使用它是了解ajax调用状态的更好选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM