2017-12-25 15 views
0

次のコードは、のcontent-container div内にロードされます。次に、別のスクリプトinnerStuff.htmlsubmit_entry()とし、innerStuff.htmlのフォームを送信します。私は得たものiOSのみの問題:<script>をAJAX経由で読み込んだHTMLは実行されません

:ボタンのをクリック、innerStuff.htmlsubmit_entry()(AJAXを介してロード)は、任意のブラウザ上でのiOS上のものを除いてを実行します。

私が知る限り、これは私がiOSで遭遇する唯一の問題です。他のプラットフォームを使用している場合は、この関数が機能します。

index.html

//Normal HTML stuff above 
<div id="content-container"></div> 
//Normal HTML stuff 
<script> 
getStuff = function(filename){ 
    $.ajax({ 
     type: "POST", 
     url: "https://website.com/ajax/", 
     data: { 
      'name': filename 
     }, 
     success : function(data){ 
      $('#content-container').animate({opacity: '0'}, 250, function(){$('#content-container').html(data);}); 
      $('#content-container').animate({opacity: '1'}, 250); 
     } 
    }); 
}; 

getStuff('innerStuff'); //Gets innerStuff.html 
</script> 

innerStuff.html

<div id="form-container"> 
    <form enctype="multipart/form-data" method="post" id="form"> 
     //Normal form stuff here (>5 elements) 
    </form> 
    <button id="submit-btn" onclick="javascript:submit_form();">Submit</button> 
    <script> 
     form['2'].value = "Something"; //The default value (the form has >5 elements, and is the only form on the website) 
     submit_form = function() { 
      alert("Submitting form. Please wait..."); 
      $.ajax({ 
       url : "https://website.com/submitform/", 
       type : "POST", // https method 
       data : new FormData(form), 
       contentType: false, 
       processData: false, 

       // handle a successful response 
       success : function(json) { 
        if(json['result'] == 'error'){ 
         alert(json); 
        } 
        else{ 
         alert('Submission successfull!'); 
        } 
       }, 

       // handle a non-successful response 
       error : function(xhr,errmsg,err) { 
        if(xhr.status == 0){ 
         alert("We can't seem talk to the server.\nPlease reconnect and try again."); 
        } 
        else{ 
         alert("Oops! We have encountered an error: " + xhr.status + "\nDetails: " + xhr.responseText); 
        } 
       } 
      }); 
     }; 
    </script> 
</div> 
+0

を{getStuff( 'innerStuff');}' getStuff() '@AndreiTodorut –

+0

'だけで正常に動作します。これは 'submit_form()'の問題です。 – Steve

答えて

0

次のようにポインタするボタンにカーソルを設定してみてください。

#submit-btn {cursor: pointer;} 

私は知っているが、iOSはonClick()で奇妙なバグがあります。

+0

動作しません。問題は依然として存在します。 – Steve

+0

javascript接頭辞とセミコロンを削除する必要はありません。だからJavascript:onClick()onClick()する必要があります。 –

0

このお試しください: `window.onload =関数()してみてください

<script> 
 
getStuff = function(filename){ 
 
    $.ajax({ 
 
     type: "POST", 
 
     url: "https://website.com/ajax/", 
 
     data: { 
 
      'name': filename 
 
     }, 
 
     success : function(data){ 
 
      $('#content-container').animate({opacity: '0'}, 250, function(){ 
 
\t \t \t \t $('#content-container').html(data); 
 
\t \t \t \t /* Add this */ 
 
\t \t \t \t var arr = $('#content-container')[0].getElementsByTagName('script') 
 
\t \t \t \t for (var n = 0; n < arr.length; n++) 
 
\t \t \t \t eval(arr[n].innerHTML) 
 
\t \t \t }); 
 
      $('#content-container').animate({opacity: '1'}, 250); 
 
     } 
 
    }); 
 
}; 
 

 
getStuff('innerStuff'); //Gets innerStuff.html 
 
</script>

+0

これを使用すると、iOSブラウザはフォームにまったく読み込まれません。代わりに、フォームが使われていた空白のスペースが得られます。 – Steve

関連する問題