次のコードは、のcontent-container
div内にロードされます。次に、別のスクリプトinnerStuff.html
をsubmit_entry()
とし、innerStuff.html
のフォームを送信します。私は得たものiOSのみの問題:<script>をAJAX経由で読み込んだHTMLは実行されません
:ボタンのをクリック、innerStuff.html
でsubmit_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>
を{getStuff( 'innerStuff');}' getStuff() '@AndreiTodorut –
'だけで正常に動作します。これは 'submit_form()'の問題です。 – Steve