2014-10-16 4 views
-4
   var id = -1; 

       function addMSG(dataz) { 
        console.log(dataz); 
       } 

       function waitForMsg() { 
        console.log("start waitmsg"); 
        $.ajax({ 
         url: "chatxml2.php", 
         type: "POST", 
         async: true, 
         cache: false, 
         timeout: 1000, 
         data: {id: id, chat: '.filter_input(INPUT_GET,"id").'}, 
         datatype: "xml", 


         done: function(dataz) { 
          //addmsg(nera reikia); 
          addMSG(dataz); 
          console.log("success"); 
         }, 

         fail: function(XMLHttpRequest, textStatus, errorThrown){ 
          //addmsg("error", textStatus + " (" + errorThrown + ")"); 
          waitForMsg(); 
          console.log("fail"); 
         } 
        }); 
       } 

       $(document).ready(function(){ 
        console.log(id); 
        waitForMsg(); 
       }); 

어떤 이유로 든이 결과가 없습니다. "데이터"를 올바르게 사용하고 있는지 확실하지 않습니다. 잠시 동안 검색해 보았지만 해결할 수없는 것처럼 보였습니다. js에서는 상당히 나쁩니다.AJAX 요청이 어떤 이유로 든 결과를 얻지 못합니다.

PHP 스크립트가 100 % correcly를 (를) 사용하고 있으며 HTML 스크립트 게시물로 시도했습니다.

+1

'$ .ajax'는 옵션 객체에서'done :'과'fail :'속성을 읽지 않습니다. 'fixit : function() {alert ("hi");}'를 사용하는 http://api.jquery.com/jQuery.ajax –

+0

도 아무 것도하지 않습니다. –

답변

1

구문이 잘못되었습니다. donefail은 각각 successerror이어야합니다.

그래서 그것은해야한다 : 당신이 다음 이연 구문을 사용하려면

$.ajax({ 
    url: "chatxml2.php", 
    type: "POST", 
    async: true, 
    cache: false, 
    timeout: 1000, 
    data: {id: id, chat: '.filter_input(INPUT_GET,"id").'}, 
    datatype: "xml", 
    success: function(dataz) { 
     //addmsg(nera reikia); 
     addMSG(dataz); 
     console.log("success"); 
    }, 
    error: function(XMLHttpRequest, textStatus, errorThrown){ 
     //addmsg("error", textStatus + " (" + errorThrown + ")"); 
     console.log("fail"); 
    } 
}); 

은은 다음과 같습니다

$.ajax({ 
    url: "chatxml2.php", 
    type: "POST", 
    async: true, 
    cache: false, 
    timeout: 1000, 
    data: {id: id, chat: '.filter_input(INPUT_GET,"id").'}, 
    datatype: "xml" 
}).done(function() { 
    addMSG(dataz); 
    console.log("success"); 
}).fail(function() { 
    console.log("fail"); 
}); 
0

이 성공에 의해 수행 교체 및 오류

읽기가 실패 이연에 대해 aviable 완료 및 실패에 대한 개체입니다.

관련 문제