2017-03-15 46 views
0

在離子2框架上使用以下代碼時,Android上的所有內容都很好,但是當我將其轉換爲iOS時,只有以下代碼不起作用。我一直在嘗試過去兩天。DOM中的注入表單未提交

如果有人可以看一看,並告知發生了什麼。

import { Component } from '@angular/core'; 
import { NavController } from 'ionic-angular'; 

    @Component({ 
     selector: 'page-home', 
     templateUrl: 'home.html' 
    }) 
    export class HomePage { 

     constructor(public navCtrl: NavController) {} 

     proceedToPayment(){ 

     var mapForm = document.createElement("form"); 
     mapForm.target = "_blank";  
     mapForm.method = "POST"; 
     mapForm.action = "http://www.example.com/api/checkout.php"; 

     // Create an input 
     var firstname = document.createElement("input"); 
     var lastname = document.createElement("input"); 

     firstname.type = "text"; firstname.name = "firstname"; firstname.value = "John"; 
     lastname.type = "text"; lastname.name = "lastname"; lastname.value = "Doe"; 

     // Add the input to the form 
     mapForm.appendChild(firstname); 
     mapForm.appendChild(lastname); 

     document.body.appendChild(mapForm); 
     mapForm.submit(); 

     } 

    } 
+0

的iOS將防止不安全的URL時的消耗。你必須添加一個鍵值到Info.plist,檢查這個答案 - > http://stackoverflow.com/questions/30731785/how-do-i-load-an-http-url-with-app -transport-security-enabled-in-ios-9 –

+0

@camaron我也試過這個,但它仍然不起作用。 –

+0

更改爲https? ..我不認爲iOS允許HTTP了.. –

回答

0

您需要安裝cordova-plugin-whitelist。 如果您還沒有,請運行ionic plugin add cordova-plugin-whitelist

然後加入<allow-navigation href="http://*/*" />config.xml中

+0

感謝您的答案。我已經嘗試過了,但它仍然不起作用。你有任何其他解決方案? –

+0

我已更新協議,它是'https'而不是'http',請嘗試更改。 –