[英]How to append a <script></script> along with other data returned from another page when using Jquery ajax?
[英]Populate div with data returned from another page using JQuery and AJAX
我有一個表單,提交后會去blah.php
。 問題是, blah.php
移至另一個域。 JQuery看到了這一點,並給出了302 Object Moved error
。 因此,我不得不使用JSON
和AJAX
來發送表單。 注釋詳細信息在下面的Jquery代碼內。
該流程應該是單擊按鈕,檢查服務器端,如果不是'ok'
的響應,在狀態DIV輸出響應,並在該網頁上停止所有服務器端。 如果回答為'ok'
,則讓表單繼續進行
快速模擬我的代碼
<form id="ppform" method="post" action"blah.php">
<input id="someid" type="text" />
<button id="sendbutton">Send</button>
<div id="status"></div>
</form>
$(document).ready(function(){
$(document).on('click', '#sendbutton', function(){
$('#status').empty();
$.ajax({
type: "POST",
url: "blah.php",
data: reqBody,
dataType: "json",
success:function(data,textStatus){
// here I want the div to return data if the response isn't 'ok'
if(data!='ok'){
$('#status').append(data);
}else{
// response was 'ok' so empty div,
// show loading gif and submit the form
$('#status').empty().html('<div id="proc">Processing</div><img src="loading.gif" />');
if (data.redirect){
window.location.href = data.redirect;
} else {
$("#ppform").replaceWith(data.form);
}
}
}
});
});
});
我認為,這是瀏覽器安全問題,您不能在其他域上發送Ajax請求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.