2014-09-01 3 views
2

웹 페이지에서 데이터를 가져 오기 위해 티타늄으로 된 작은 코드를 만들었습니다. 하지만 응용 프로그램을 실행하고 기능을 트리거하는 버튼을 누르면 데이터가 표시되지 않습니다.티타늄의 웹 페이지에서 데이터 가져 오기

누군가 내가 잘못하고있는 것을 설명 할 수 있습니까? 왜 잘못 했나요? 그것은 HYA 보여줍니다, 나는 거기 얻을 수 있는지 확인하는 기능에 생 Ti.API.info('hya')을 뒀다

// include needed files 
Ti.include('responsive.js'); 
//Ti.include('http_connection.js'); 


//Create the screen 

//The home screen 
var homeWindow = Ti.UI.createWindow({ 
    exitOnClose: true, 
    fullscreen: false, 
    title: 'Advanced' 
}); 

var homeView = Ti.UI.createView({ 
    backgroundColor: 'white' 
}); 

var homeLabel = Ti.UI.createLabel({ 
    top: 20, 
    left: 30, 
    height: 30, 
    text: 'Test text', 
    color: 'black', 
    font: {fontSize: 18} 
}); 

var testButton1 = Ti.UI.createButton({ 
    title: 'test', 
    backgroundColor: 'red', 
    top: 55, 
    left: per10, 
    width:per60, 
    height: 30, 
    color: 'black', 
    font: {fontSize: 14} 
}); 

var testButton2 = Ti.UI.createButton({ 
    title: 'test2', 
    backgroundColor: 'blue', 
    top: 95, 
    left: per10, 
    width:per60, 
    height: 30, 
    color: 'black', 
    font: {fontSize: 14} 
}); 

testButton2.addEventListener('click',function(e){ 
    Ti.API.info("Button Clicked"); 
    http_con(); 
    Ti.API.info("Button Clicked 2"); 
    //alert('test'); 
}); 

function http_con() { 
    Ti.API.info('hya'); 

    //Database connection 
    var http_client = Ti.Network.createHTTPClient(); 
    http_client.open('POST', 'http://rdbomers-hp:89/ceres'); 

    //If variables has been send 
    http_client.onload = function() { 
     Ti.API.info('subjects: ' + this.responseText); 
     callback(this.responseText); 
    }; 

    //If there is an error 
    http_client.onerror = function(e) { 
     Ti.API.info('error: ' + JSON.stringify(e)); 
    }; 
}; 

//Creating the application 
//Home screen 
homeWindow.add(homeView); 
homeView.add(homeLabel); 
homeView.add(testButton1); 
homeView.add(testButton2); 
homeWindow.open(); 

,하지만 난 그것을 웹 페이지의 내용을 표시하려면 :

내 코드입니다.

+0

처럼, 해당 페이지가 온라인인지 확인해야한다. http : // rdbomers-hp : 89/ceres -> 0 POST 또는 GET으로 응답 없음 (Chrome 확장 - 고급 나머지 클라이언트) –

+0

페이지가 온라인 상태이며 로컬 호스트 서버 –

+0

이 가져올 요청 유형을 설정하고 확인합니다. 작동하는 경우 브라우저에서 URL을 열어보십시오. 그렇지 않으면 열어 보시고 그렇지 않으면 장치에서 액세스 할 수 있는지 확인해야 할 수 있습니다. – Dragon

답변

0

당신은 .open를 호출하기 전에 콜백을 정의해야합니다 - 먼저이

function http_con() { 
    Ti.API.info('hya'); 

    //Database connection 
    var http_client = Ti.Network.createHTTPClient(); 

    //If variables has been send 
    http_client.onload = function() { 
     Ti.API.info('subjects: ' + this.responseText); 
     callback(this.responseText); 
    }; 

    //If there is an error 
    http_client.onerror = function(e) { 
     Ti.API.info('error: ' + JSON.stringify(e)); 
    }; 

    http_client.open('POST', 'http://rdbomers-hp:89/ceres'); 

}; 
관련 문제