I can't do operations after a success of AJAX call

I can't do operations after a success of AJAX call

Hi, i noted that calling a php script with this syntax

  1. $.ajax({
  2.                     url: scriptUrl,
  3.                     type: "POST",
  4.                     data: formdata,
  5.                     processData: false,
  6.                     contentType: false,
  7.                      success: function (res)
  8.                       {                         
  9.                           alert (res) //<----This is showed ("success")
  10.                           if(res=="success")  //<-----------PROBLEM HERE
  11.                           {alert("All gone ok")}  <---- This is NOT showed
  12.                       }
  13.               })

this happen because i dont regularly exit from the php script... In fact if i place "exit;" after the response:
  1. echo("success");
  2. exit;

 the if statament of the "success" function of ajax regularly works..

Why happen this? I would want to know how ajax works theorically