Javascript 无法使用来自AJAX请求的字符串结果

Javascript 无法使用来自AJAX请求的字符串结果,javascript,php,ajax,Javascript,Php,Ajax,我遇到的问题是,我似乎无法使用从请求调用的PHP文件传递回原始JS文件的结果。这是结果和处理程序: if(creds_verification() == true){ $.ajax({ url:"scripts/scripts.php", //the page containing php script type: "post", //request type, dataType: 'json', data: {ur

我遇到的问题是,我似乎无法使用从请求调用的PHP文件传递回原始JS文件的结果。这是结果和处理程序:

if(creds_verification() == true){
        $.ajax({
        url:"scripts/scripts.php", //the page containing php script
        type: "post", //request type,
        dataType: 'json',
        data: {url: URL, user: USER, password: PASS},
        success:function(result){
            var verdict = result
            if(verdict == "Yes"){
               Call another external function 
            }else{
            console.log(results.abc)
         }
       }
     });
    }
控制台不断地打印“是”,也就是结果的结果。abc。。。为什么会发生这种情况?它应该正在执行下一个函数

添加信息 运行shell命令并回显结果的PHP脚本:

scripts.php


这是因为您在服务器上调用的代码意味着scripts/scripts.php的结果,而不是返回“Yes”,因为结果是将“Yes”放在返回对象的abc属性中

将php代码更改为:

<?php  
$URL = $_POST['url'];
$USER = $_POST['user'];
$PASSWORD = $_POST['password'];

$res = shell_exec("PATH.../phantomjs PATH/phantom/examples/test.js 2>&1 $URL $USER $PASSWORD");
echo json_encode($res == 'Yes' ? $res : array("abc"=>$res));
?>
而javascript

if(creds_verification() == true){
        $.ajax({
        url:"scripts/scripts.php", //the page containing php script
        type: "post", //request type,
        dataType: 'json',
        data: {url: URL, user: USER, password: PASS},
        success:function(result){
            if(result == "Yes"){
               Call another external function 
            }else{
               console.log(result)
         }
       }
     });
    }

没有足够的详细信息可能是:verdict==Yes,计算结果不为true,并且您的函数不会被调用。记录结果。您确定结论等于结果吗?似乎您正在覆盖内容。始终使用===而不是==@PaoloMangia它不应该计算为true或false,而是检查结果的值是否等于字符串Yes,然后做出相应的响应。我做了这些更改,还尝试了ifresult.abc==Yes,但是他们两个都不起作用。这不总是会回来吗?是的?它应该返回test.js确定的是或否?在上面的脚本中没有。如果结果为“是”,则仅返回“是”;否则,它将使用abc键创建一个数组,其值作为test.js的结果。如果结果为“是”或“否”,则不需要abc属性。只需返回echo json_encode$res;你完成了。那么,在javascriptI中完全忘记abc吧,我已经做了这些更改,但同样的情况正在发生。else参数正在触发,并在控制台中打印Yes
<?php  
$URL = $_POST['url'];
$USER = $_POST['user'];
$PASSWORD = $_POST['password'];

$res = shell_exec("PATH.../phantomjs PATH/phantom/examples/test.js 2>&1 $URL $USER $PASSWORD");
echo json_encode($res == 'Yes' ? $res : array("abc"=>$res));
?>
<?php  
$URL = $_POST['url'];
$USER = $_POST['user'];
$PASSWORD = $_POST['password'];

$res = shell_exec("PATH.../phantomjs PATH/phantom/examples/test.js 2>&1 $URL $USER $PASSWORD");
echo json_encode(preg_replace("/[^A-Za-z]/", '', $res));
?>
if(creds_verification() == true){
        $.ajax({
        url:"scripts/scripts.php", //the page containing php script
        type: "post", //request type,
        dataType: 'json',
        data: {url: URL, user: USER, password: PASS},
        success:function(result){
            if(result == "Yes"){
               Call another external function 
            }else{
               console.log(result)
         }
       }
     });
    }