2013-08-23 27 views
9

Tôi đang phát triển một ứng dụng PhoneGap. Khi tôi kiểm tra ứng dụng của mình trong trình duyệt thì không có vấn đề gì. Everythings hoạt động tốt. Nhưng khi tôi thử nó trong gợn, javascript của tôi không hoạt động. Cụ thể: Người dùng có thể đăng nhập hệ thống và nếu nó chuyển hướng thành công đến một trang khác (sử dụng jquery mobile), nó hoạt động tốt trong chrome, internet explorer và firefox. Nhưng không làm việc trong gợn sóng. Mã của tôi được hiển thị dưới đây:Ứng dụng PhoneGap không hoạt động trên Google Ripple

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> 
    <meta name="apple-mobile-web-app-capable" content="yes"> 
    <meta name="apple-mobile-web-app-status-bar-style" content="black"> 
    <title></title> 
    <link rel="stylesheet" href="css/jquery.mobile-1.3.2.css"> 

    <script src="js/jquery-1.10.2.js"></script> 
    <script src="js/jquery.mobile-1.3.2.js"></script> 
    <script src="js/jquery.base64.js"></script> 
    <script src="js/cordova.js"></script> 
    <script type="text/javascript"> 
     $(function() { 
      var credentials = 'admin:adminabc'; 
      var authType = "Basic " + credentials; 
      $('#loginForm').submit(function() { 
       $.ajax({ 
        type : "GET", 
        url : 'http://localhost:30673/api/user/Get', 
        data : 'json', 
        beforeSend : function(xhr) { 
         xhr.setRequestHeader("Authorization", authType); 
        }, 
        success : function(data, textStatus) { 
         $.mobile.changePage("#menu", { 
          transition : "slideup" 
         }); 
        } 
       }); 
      }); 

      $("#aboutUs").click(function() { 
       $.ajax({ 
        type : "GET", 
        url : 'http://localhost:30673/api/AboutMeWA/', 
        data : 'json', 
        beforeSend : function(xhr) { 
         xhr.setRequestHeader("Authorization", authType); 
        }, 
        success : function(data, textStatus) { 
         $('#aboutMeTitle').val(data); 
        } 
       }); 
      }); 
     }); 

     function onBodyLoad() { 
      document.addEventListener("deviceready", onDeviceReady, false); 

      function onDeviceReady() { 
       document.addEventListener("pause", onPause, false); 
       document.addEventListener("resume", onResume, false); 
      } 

      function onPause() { 
       alert("paused"); 
      } 

      function onResume() { 
       alert("resume"); 
      } 

     } 
    </script> 
</head> 
<body onload="onBodyLoad()"> 
    <div data-role="page" id="mainPage"> 
     <div data-role="header" data-theme="a" > 
      <h4> Ziro </h4> 
     </div> 
     <div data-role="content"> 
      <form id="loginForm"> 
       <div data-role="fieldcontain"> 
        <label for="textinput1"> Kullanıcı Adı:  </label> 
        <input name="" id="userName" placeholder="username" value="" type="text"> 
       </div> 
       <div data-role="fieldcontain"> 
        <label for="textinput2"> Password</label> 
        <input name="" id="password" placeholder="password" value="" type="password"> 
       </div> 
       <input type="submit" data-theme="a" data- icon="arrow-r" data-iconpos="left" 
       value="Login"> 
      </form> 
      <a href="#menu" class="ui-link" data- transition="flip">Menü</a> 
     </div> 
     <div data-role="footer" data-theme="a" data-position="fixed"> 
      <h3> FF Yazılım </h3> 
     </div> 

    </div> 
    <div data-role="page" id="menu" data-add-back-btn="true" data-back-btn-text="Geri"> 
     <div data-role="header" data-theme="a" > 
      <h4> Ziro Mobilya </h4> 
     </div> 
     <div data-role="content"> 
      <ul data-role="listview" data-divider-theme="a" data- inset="true"> 
       <li data-role="list-divider" role="heading"> 
        Panel 
       </li> 
       <li data-theme="c"> 
        <a href="#about" data-transition="flip" id="aboutUs"> Hakkımızda </a> 
       </li> 
       <li data-theme="c"> 
        <a href="#page1" data-transition="slide"> Referans Resimleri </a> 
       </li> 
       <li data-theme="c"> 
        <a href="#page1" data-transition="slide"> Servis Resimleri </a> 
       </li> 
       <li data-theme="c"> 
        <a href="#page1" data-transition="slide"> Slogan </a> 
       </li> 
       <li data-theme="c"> 
        <a href="#page1" data-transition="slide"> İstatistikler </a> 
       </li> 
       <li data-theme="c"> 
        <a href="#page1" data-transition="slide"> Button </a> 
       </li> 
      </ul> 
     </div> 
     <div data-role="footer" data-theme="a" data-position="fixed"> 
      <h3> FF Yazılım </h3> 
     </div> 
    </div> 

    <div data-role="page" id="about" data-add-back-btn="true" data-back-btn-text="Geri"> 
     <div data-theme="a" data-role="header"> 
      <h3> Hakkımızda </h3> 
     </div> 
     <div data-role="content"> 
      <div style=""> 
       <img style="width: 288px; height: 100px" src="http://aknera.com/temp/default/images/background3.jpg"> 
      </div> 
      <a data-role="button" data-theme="a" href="#page1" data-icon="arrow-l" 
      data-iconpos="left"> Galeriden Resim Seç </a> 
      <div data-role="fieldcontain"> 
       <label for="textinput2"> Başlık: </label> 
       <input name="" id="aboutMeTitle" placeholder="" value="" type="text" data-mini="true"> 
      </div> 
      <div data-role="fieldcontain"> 
       <label for="textarea2"> Açıklama </label> 
       <textarea name="" id="textarea2" placeholder="" data-mini="true"></textarea>               




      </div> 
      <a data-role="button" data-theme="a" href="#page1" data-icon="alert" data-iconpos="left"> Kaydet </a> 
     </div> 
     <div data-role="footer" data-theme="a" data-position="fixed"> 
      <h3> FF Yazılım </h3> 
     </div> 
    </div> 
</body> 
</html> 

cấu trúc ứng dụng của tôi được hiển thị dưới đây:

enter image description here

Lỗi code is: xhr_proxy tinyhippos_apikey = ABC & tinyhippos_rurl = http% 3A // localhost% 3A30673/ap‌ i/user/Get% 3Fjson rippleapi.herokuapp.com Mã trạng thái: 500 Lỗi máy chủ nội bộ Tôi nhận dữ liệu từ địa chỉ bài đăng cục bộ của mình: localhost: 30673/api/user/Get '; Nó hoạt động tốt trong trình duyệt. Và nhận dữ liệu từ localhost: 30673/api/user/Get. Nhưng trong gợn nó cố gắng để có được dữ liệu từ Có: xhr_proxy tinyhippos_apikey = ABC & tinyhippos_rurl = http% 3A // localhost% 3A30673/api/u ser/Nhận% 3Fjson rippleapi.herokuapp.com

Cần chàng trai lời khuyên.

+0

Bạn có thấy bất kỳ lỗi nào trong bảng điều khiển không? –

+0

Error code là: xhr_proxy tinyhippos_apikey = ABC & tinyhippos_rurl = http% 3A // localhost% 3A30673/api/người dùng/Nhận% 3Fjson rippleapi.herokuapp.com Mã Tình trạng: 500 Internal Server Error I'am nhận dữ liệu từ địa chỉ đăng bài localhost của tôi: http: // localhost: 30673/api/user/Get ' Nó hoạt động tốt trong trình duyệt. Và nhận dữ liệu từ http: // localhost: 30673/api/user/Get. Nhưng trong gợn nó cố gắng để có được dữ liệu từ Có: xhr_proxy tinyhippos_apikey = ABC & tinyhippos_rurl = http% 3A // localhost% 3A30673/api/người dùng/Nhận% 3Fjson rippleapi.herokuapp.com – fuat

Trả lời

24

Sự cố mà bạn có thể gặp phải là bạn đang sử dụng proxy tên miền chéo của Ripple được bật trong cài đặt theo mặc định.

Tên miền chéo proxy có 3 cài đặt: "từ xa", "cục bộ" và "bị tắt". Trong trường hợp của tôi, tôi thực sự phải vô hiệu hóa nó, nhưng trong một số trường hợp, bạn sẽ có thể sử dụng "địa phương".

kịch bản có thể xảy ra:

1) ứng dụng địa phương của bạn gọi một dịch vụ từ xa ở đâu đó trên một máy chủ:

bạn hoặc sẽ sử dụng "từ xa" hay "khuyết tật" tùy thuộc vào cấu hình trên máy chủ từ xa .

2) ứng dụng địa phương của bạn là "localhost" và bạn đang thực hiện cuộc gọi đến một URL truy cập localhost:

bạn hoặc sẽ sử dụng "địa phương" hay "khuyết tật" tùy thuộc vào cài đặt tên miền chéo và như là.

3) bạn đang chạy một ứng dụng địa phương mà các cuộc gọi một máy chủ mà cũng là địa phương nhưng trong một vm hoặc một cái gì đó mà làm cho nó không thể tiếp cận đến một proxy trên "localhost":

bạn cần phải có nó đặt để "tắt" và đảm bảo máy chủ api của bạn có cài đặt cho phép yêu cầu miền chéo. Đáng chú ý nhất là bạn sẽ muốn đặt tiêu đề "Access-Control-Allow-Origin".

+0

AFAIK cho (1) kịch bản? người ta cũng có thể sử dụng "địa phương". Sử dụng proxy cục bộ là một phương pháp chuẩn để xử lý Ajax đa miền –

2

Tôi gặp vấn đề tương tự. Điều đó xảy ra khi tôi cố gắng kết nối với dịch vụ WebAPI của tôi được lưu trữ trên IISExpress.

Sau khi tôi thay đổi lưu trữ thành máy chủ cục bộ IIS của mình, lỗi này biến mất và tôi có thể kết nối với dịch vụ WebAPI bằng Ripple. Tất nhiên, bạn sẽ phải thay đổi url trỏ đến dịch vụ của bạn (trong trường hợp của bạn là http://localhost:30673).

Các vấn đề liên quan