Home:ALL Converter>Ajax query, php file is getting read but can't enter success function

Ajax query, php file is getting read but can't enter success function

Ask Time:2018-11-10T09:02:28         Author:B Payne

Json Formatter

so I have the following code that is calling a CheckEmail2.php. I know what I want to do in CheckEmail2.php but because my Ajax success is not working, I have minded the scope to just return a Json. below is my java script. When I launch my console, I see my string coming through that I am echoing in my CheckEmail2.php. so I know my php file is getting read but why won't my success function hit if my string is getting read? I can't get my success function to get called. It always goes to error.

<script type="text/javascript">
function validateForm(){
  var email = document.forms["signupform"]["email"].value;
  var result = false;
  if (email != ""){
    $.ajax({           
      type: "POST",  
      url: "/CheckEmail2.php",  
      data: { "User_Email": email },
      dataType: "json",
      success: function(resp){
        console.log(resp);
        if(resp == "Not Found"){
          result = true;
        }
        else
        {
        result = false;
        }
      },
      error: function(data, status){
        console.log(data, status);
      }
    }); //end Ajax
  }
  return result;
}
</script>

here is my PHP

<?php

    header("Content-type:application/json");
    echo json_encode("Not Found");

?>

why is error always getting called?

Author:B Payne,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/53235125/ajax-query-php-file-is-getting-read-but-cant-enter-success-function
yy