Return errors from PHP run via. AJAX?

后端 未结 4 859
轻奢々
轻奢々 2020-12-02 20:23

Is there a way to get PHP to return an AJAX error code if the PHP script fails somewhere? I was following a tutorial and typed this in to my PHP:

$return[\'error\         


        
4条回答
  •  执念已碎
    2020-12-02 20:46

    try this out. Hope it helps.

    
    
            
                
                
                
            
            
                


    Error: Fill in ALL fields.
    '; } elseif(is_numeric($_POST['name'])){ $error = '
    Error: Name should NOT contain numbers.
    '; } elseif(!is_numeric($_POST['age'])){ $error = '
    Error: Age should ONLY contain numbers.
    '; } else{ $result = '
    Hi '.$_POST['name'].', you are '.$_POST['age'].' years old.
    '; } echo $error; echo $result; ?>

提交回复
热议问题