JQuery Ajax Post Result

Hello,

I have a JQuery Ajax script that posts form data to a page. The page runs a stored procedure that returns a recordset. If the recordset data returned = 1 then I want to do a success action, if 2 then a fail action...

$("#Register").submit(function(e){
      e.preventDefault();
    $.ajax({
		type: "POST",
        url: "/actions/jbe.asp",
        data:$(this).serialize(),
        success:function(result){
     		 $(this).fancybox.close();
			 location.reload();
  								  }});
  });

Open in new window


How do I add this if 1 then success:function, if 2 then failure action.

Also How do a select a button with a class option ----

$(button.closefb).click(function(){
 $(this).fancybox.close();
});

Open in new window


thank you
garethtnashAsked:
Who is Participating?
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
$("#Register").submit(function(e){
      e.preventDefault();
    $.ajax({
		type: "POST",
        url: "/actions/jbe.asp",
        data:$(this).serialize(),
        success:function(result){
          if(result==1){
            // do something success
          }else {
            // do something fail
          }
          
     		 $(this).fancybox.close();
			 location.reload();
  								  }});
  });

Open in new window


Also How do a select a button with a class option ----
<button class="option">submit</button>

$('button.option').click(function(){
  //do something
});

Open in new window

0
 
garethtnashAuthor Commented:
Thanks Scott
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.