简体   繁体   中英

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. The image has an href tag so on its click, it opens some page in other tab. The purpose of doing ajax call here is I'm just saving the user clicks on the image for telemetry purpose in database table. Hence I'm not returning anything from ajax call. So is it necessary to have "success" as a parameter in my ajax call?

      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.

Success is an option in ajax call. If you don't want it you can skip it, But using it is a better choice for knowing the ajax call status.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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