2014-12-23 141 views
0

我有我的HTML頁面的AJX呼叫我的成功調用JSON數據類型的響應:爲什麼行爲不正確

$.ajax({url:"forgetpwd.php",datatype:'json',type:'post',success:function(result){ 
         alert(result); 
         alert(result.status); 
         if(result.status == "success") 
          $("#dialog").dialog("open"); 
         alert('Done'); 
        }}); 
      }); 

我forgetpwd.php PHP代碼是如下:

<?php 
//mail($to,$subject,$message,$headers); 
$response['status'] = 'success'; 
echo json_encode($response) 
?> 

我的第一個成功警告AJAX功能顯示了以下值:

{"status":"success"} 

但第二個顯示的值爲undefined,而所有其他警報混亂年齡也越來越顯示?爲什麼result.status變量的值是'undefined'?

+1

我認爲它應該是用於智能猜測的'dataType',而不是'datatype' –

+2

'datatype'中的錯字應該是camelCase'dataType'。 – charlietfl

+0

@charlietfl哦,是的。請把這個作爲答案。 –

回答

1

按照註釋的答案上面這個問題

**datatype** should be camelCase **dataType** 

像下面的代碼

$.ajax({url:"forgetpwd.php",dataType :'json',type:'post',success:function(result){ 
        alert(result); 
        alert(result.status); 
        if(result.status == "success") 
         $("#dialog").dialog("open"); 
        alert('Done'); 
       }}); 
     }); 
0
$.ajax({url:"forgetpwd.php",dataType :'json',type:'post',success:function(result){ 
         alert(result); 
         alert(result.status); 
         if(result.status == "success") 
          $("#dialog").dialog("open"); 
         alert('Done'); 
        }}); 
      }); 

錯字在的dataType ==>請參閱此http://api.jquery.com/jquery.ajax/