JS Notification Popup Upon Error / Success

Hi All

I’m a bit stuck, i’m currently rewriting an application in codeigniter for educational purposes and on the ajax forms, upon submit i would like it to fire the relevant notification window depending on whether the call was a success or an error occurred. I can fire the standard alert but i’m not sure how to fire an alert i’ve created myself. I know the notification popup works as i put it inside of the button and it fired but would like it to fire depending on the result.

I have tried googling but can’t seem to find the answer that fits the bill. All of the results are just third party plugins.

Any help would be greatly appreciated:

$.ajax({
  url: '/ajax-RequestPost',
  type: 'POST',
  data: {enquiry: enquiry, name: name, email: email, contactno: contactno, note: note, status: status},
    error: function() {
    alert('OOPS Something Went Wrong'); // id="position-4-error"
    },
    success: function(data) {
    alert("Record added successfully");  
    }
  });

Thanks in advance all.

Hi @oli_d111, well what does that custom alert look like? The general approach though would be to hide any such messages initially and then just show them when appropriate, along the lines of

<div id="error-message" hidden>
  Something went wrong
</div>

<div id="success-message" hidden>
  Record added successfully
</div>
$.ajax({
  // ...
  success: function () {
    $('#success-message').show()
  },
  error: function () {
    $('#error-message').show()
  }
})
1 Like

You sir, are a legend. Thank you. That is just what I needed. I’ve only just started learning JS and this is perfect. :+1:t2:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.