Home:ALL Converter>Why the control is not getting returned from PHP file to AJAX success function?

Why the control is not getting returned from PHP file to AJAX success function?

Ask Time:2015-12-30T19:32:24         Author:PHPLover

Json Formatter

I'm using PHP, Javascript, AJAX for my website.

I'm putting below only the necessary code.

JS code(AJAX function code):

$("#btn_add_event").click(function(){

    var strSeriaze = $( "#formAddEvent" ).serialize();
    url = $( "#formAddEvent" ).attr('action');
    $("#btn_add_event").attr('disabled', 'disabled');
    $("#addEventErrorMsg").html('');
    $.ajax({
        url: url,
        type: "POST",
        data:  {postData:strSeriaze},
        beforeSend: function(){
            $('#loader-icon').show();
        },
        complete: function(){
            $('#loader-icon').hide();
        },
        success: function(data){
        //Control is not returning here on success from PHP file
            $('#loader-icon').hide();

            if(data == "Success")
            {
                $("#myModal-add-event").modal('hide');
                $("#myModal-add-event").hide();
                window.location.href = site_url + "event_index.php";
                return false;
            }
            else
            {
                $("#btn_add_event").attr('disabled', false);
                $("#addEventErrorMsg").show();
                $("#addEventErrorMsg").html(data);
            }
        },
        error: function(){}
    });   
  }) 

I tried to debug the issue the call is going perfectly to PHP file, the logic written over there is also working but the control is not getting returned to the js file(i.e. AJAX success function). In turn I'm unable to execute code written inside success function.

Please correct the mistake I'm making in my code.

Following is the necessary PHP code after execution it is expected to return the control to js file(i.e. AJAX success funtion) but it's not happening.

if($ret) {
  $eventAddResultArr = $objEvent->GetResponse();

  if($eventAddResultArr['msg'] == 'Success') {
    echo "Success";
    exit;
  //From here it is expected to return the control to js file's AJAX success function but it's stopping execution here only
  } else {
    $errMsg = "";
    foreach($eventAddResultArr['msg'] as $key => $err_msg) {
      $errMsg .= $err_msg."<br>";
    }       
    echo $errMsg;
    exit;
  }
}

Note : I've put in comments in my code to make you understand my issue better. Still if you need any further information regarding the issue I'm facing please do let me know.

Thanks.

Author:PHPLover,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/34528704/why-the-control-is-not-getting-returned-from-php-file-to-ajax-success-function
devpro :

If you are not using DataType in ajax than you can follow this:\n\nIn php \n\nUse echo true; instead of echo \"Success\"; \n\nAnd in Ajax, check with:\n\nif(data == true) {\n//your code\n}\n",
2015-12-30T11:52:05
yy