Jquery ajax POST method not working : I am trying to execute the ajax operation. the call is working fine but the problem I am having is that I am getting an empty string as a response. there is no error in the console. all I get is an empty string. Even when I change the dataType to JSON, I still get the same response.

Javascript Code:

    $.ajax({
        url: "data/saveCart.php",
        method: "POST",
        data:
        {
            cartItem:item
        },
        dataType: "text",
        success: function(data){
            console.log(data);
        }
    });

PHP code:

    if(isset($_POST['cartItem']))
    {
      echo "AJAX successful";
    }
    else
    {
      echo "AJAX failed";
    }