2011-08-11 1 views
2

web5ql 데이터베이스를 사용하는 HTML5에 모바일 앱이 있습니다. 데이터베이스와 함께 다양한 CRUD 작업을 수행하는 많은 기능을 가진 data.js 파일이 있습니다. 이 함수를 연결하기 전까지는이 문제가 발생하지 않았습니다. 기본적으로이 응용 프로그램은 소매업자를위한 인용문을 작성하기위한 것이며, 필자가 작성한 함수는 따옴표 및 따옴표 줄을 가져와 JSON 객체의 배열로 변환하고 웹 응용 프로그램에 ajaxing하는 것입니다.내 websql 트랜잭션이 실행되지 않습니다

내 db.transaction이 실행되지 않고 있습니다. 왜 그런지 알아낼 수있게 도와 줄 수 있니? 다른 함수가이 정확한 SQL을 호출하면서 db가 존재합니다. 그러나 그것은 그들을 위해 작동하지이 하나

function syncQuote(){ 
    var quote_id = localStorage["quote_id"]; 

    var header = new Array(); // holds id, created, appointment_id 

    db = openDatabase("Quote", "0.1", "A collection of quotes.", 200000); 

    if(!db){ 
     console.log('Failed to connect to database.'); 
    } 

    console.log('Getting quote header data.'); 
    db.transaction(
     function(tx) { 
      tx.executeSql("SELECT * FROM quote_header WHERE id = ?", [quote_id], 
       function(tx, results) { 

        var len = results.rows.length; 
        for(var i=0; i< len; i++){ 
         alert('booyah!'); 
         header['quote_id'] = results.rows.item(i).id; 
         header['appointment_id'] = results.rows.item(i).appointment_id; 
         header['created'] = results.rows.item(i).created; 
        } 
       }); 
     }, 
     function(tx, error){ 
      console.log(error.message); 
     } 
     ); 

    // now get all quote lines for this quote 

    var lines = new Array(); 
    console.log('getting quote lines'); 
    db.transaction(
     function(tx) { 
      tx.executeSql("SELECT DISTINCT areas.label as area, features.label as feature, products.label as product, hours, price, colour FROM quote_line JOIN areas ON quote_line.area_id = areas.area_id JOIN features ON quote_line.feature_id = features.feature_id JOIN products ON quote_line.product_id = products.product_id WHERE quote_line.quote_id = ?", [quote_id], 
       function(tx, results) { 

        len = results.rows.length; 
        for(var i=0; i< len; i++){ 
         var area= results.rows.item(i).area; 
         var feature= results.rows.item(i).feature; 
         var product= results.rows.item(i).product; 
         var hours= results.rows.item(i).hours; 
         var price= results.rows.item(i).price; 
         var colour= results.rows.item(i).colour; 

         lines[i] = new Array(6); 
         lines[i][0] = area; 
         lines[i][1] = feature; 
         lines[i][2] = product; 
         lines[i][3] = hours; 
         lines[i][4] = price; 
         lines[i][5] = colour; 

        } 

       }, 

       function(tx, error){ 
        console.log(error.message); 
       } 
      ); 
     } 
    ); 

    var data = new Array(2); 
    data[0] = JSON.stringify(header); 
    data[1] = JSON.stringify(lines); 

    alert(data[0]); 
    alert(data[1]); 

    // post data to web app 
    var url = "http://*****.com/import_quote"; 

    $.ajax({ 
     type: 'POST', 
     url: url, 
     data: data, 
     success: quote_sync_success, 
     dataType: 'JSON' 
    }); 

} 

둘 다 성공을하고 콜백 실패하지만 어느 쪽도 응답하지 않습니다.

JS 앱에서 JSON을 게시하는 것은 이번이 처음이므로 의견을 말씀해주십시오.

감사합니다,

빌리

답변

0

당신이 당신의 성공 콜백의 시작에 CONSOLE.LOG()의 던지는 봤어? 렌 그 0 인 경우, 당신은

+0

를 작동하는 경우, 그리고 가지도 성공이나 오류 콜백 콘솔입니다 않을 것이다 .log가 해고 당하고 있습니다. – iamjonesy

1

복사 편집 한 코드와 같이 그들로부터 어떠한 출력을 얻을 볼은 내가 가진

function syncQuote(){ 
    var quote_id = localStorage["quote_id"]; 

    var header = new Array(); // holds id, created, appointment_id 

    db = openDatabase("Quote", "0.1", "A collection of quotes.", 200000); 

    if(!db){ 
     console.log('Failed to connect to database.'); 
    } 

    console.log('Getting quote header data.'); 
    db.transaction(
     function(tx) { 

     // CORRECTION 1: THE ? IS MEANT TO BE IN A BRACKET 
      tx.executeSql("SELECT * FROM quote_header WHERE id = (?)", [quote_id], 
       function(tx, results) { 

        var len = results.rows.length; 
        for(var i=0; i< len; i++){ 
         alert('booyah!'); 
         header['quote_id'] = results.rows.item(i).id; 
         header['appointment_id'] = results.rows.item(i).appointment_id; 
         header['created'] = results.rows.item(i).created; 
        } 
       }); 
     }, 
     function(tx, error){ 
      console.log(error.message); 
     }, 

    //CORRECTION 2 
    //THERE IS MEANT TO BE A SUCCESS CALL BACK FUNCTION HERE  
    function(){ 
     console.log('Query Completed') 
    }  

     ); 

    // now get all quote lines for this quote 

    var lines = new Array(); 
    console.log('getting quote lines'); 
    db.transaction(
     function(tx) { 

       // CORRECTION 3: WRONG CALL METHOD AND NONE-USE OF BRACKETS and QOUTES 
      tx.executeSql("SELECT DISTINCT areas.label as area, features.label as feature, products.label as product, hours, price, colour FROM quote_line JOIN areas ON quote_line.area_id = 'areas.area_id' JOIN features ON quote_line.feature_id = 'features.feature_id' JOIN products ON quote_line.product_id = 'products.product_id' WHERE quote_line.quote_id = (?)", [quote_id], 
       function(tx, results) { 

        len = results.rows.length; 
        for(var i=0; i< len; i++){ 
         var area= results.rows.item(i).area; 
         var feature= results.rows.item(i).feature; 
         var product= results.rows.item(i).product; 
         var hours= results.rows.item(i).hours; 
         var price= results.rows.item(i).price; 
         var colour= results.rows.item(i).colour; 

         lines[i] = new Array(6); 
         lines[i][0] = area; 
         lines[i][1] = feature; 
         lines[i][2] = product; 
         lines[i][3] = hours; 
         lines[i][4] = price; 
         lines[i][5] = colour; 

        } 

       }, 

       function(tx, error){ 
        console.log(error.message); 
       } 
      ); 
     } 
    ); 

    var data = new Array(2); 
    data[0] = JSON.stringify(header); 
    data[1] = JSON.stringify(lines); 

    alert(data[0]); 
    alert(data[1]); 

    // post data to web app 
    var url = "http://*****.com/import_quote"; 

    $.ajax({ 
     type: 'POST', 
     url: url, 
     data: data, 
     success: quote_sync_success, 
     dataType: 'JSON' 
    }); 
}