2014-10-28 2 views
0

ajax 콜백을 사용하지만 경고하지 않고 일부 데이터에 경고하려고합니다.Ajax 데이터 응답 데이터에 경고하지 않음

<script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js?ver=4.0'></script> 
<script> 
var mainObject = { 
     myFunction: function() { 
     $.ajax('ajax.php',function(data){ 
      alert(data); 
      //$('#test123').html(data); 
     }); 
    } 
}; 
</script> 
<div id="test123"></div> 
<a href="javascript:mainObject.myFunction();">Click here</a> 

내가 응답 Hello World!!!을 받고 있지만 경고하고 있지 않다

<?php echo "Hello World!!!"; ?> 

ajax.php. 위의 코드를 확인하십시오. 당신이 얻을 경우

var mainObject = { 
     myFunction: function() { 
     $.post('ajax.php',function(data){ 
      alert(data); 
      //$('#test123').html(data); 
     }); 
    } 
}; 

답변

0

사용 $.post처럼 시도 대신 $.ajax

코드 아약스에 success 기능을 사용해야합니다 성공하면 데이터를 경고합니다. t 오류 메시지

$.ajax('ajax.php',success:function(data){ 
     alert(data); 
    } 
error:function() 
{ 
alert("error"); 
} 
}); 
+0

예'$ .post'를 사용해보십시오. 감사. – Developer

1

당신은

$.ajax('ajax.php',{ 
     success : function(data){  // Response from the php file 
       alert(data); 
      } 
}); 
0

나를 위해 잘 작동이

<script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js?ver=4.0'></script> 
<script> 
var mainObject = { 
     myFunction: function() { 
     $.ajax({ 
      url : 'ajax.php', 
      success:function(data){ 
      alert(data); 
      } 
     }); 
      //$('#test123').html(data); 
     } 
    } 

</script> 
<div id="test123"></div> 
<a href="javascript:mainObject.myFunction();">Click here</a>