2015-12-30 11:32 阅读 30


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

I'm putting below only the necessary code.

JS code(AJAX function code):


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

            if(data == "Success")
                window.location.href = site_url + "event_index.php";
                return false;
                $("#btn_add_event").attr('disabled', false);
        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";
  //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;

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.


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    duanjiuhong5843 duanjiuhong5843 2015-12-30 11:52

    If you are not using DataType in ajax than you can follow this:

    In php

    Use echo true; instead of echo "Success";

    And in Ajax, check with:

    if(data == true) {
    //your code
    点赞 评论 复制链接分享
  • doujianchao7446 doujianchao7446 2015-12-30 11:45

    Just remove the exit; it would be the problem, especially there's no need for it.

    点赞 评论 复制链接分享