jQuery によってトリガーされた GET リクエストから HTML フォームを返そうとしていますが、これを行う方法がわかりません。顧客のサーバーが私のサーバーを呼び出し、フォームが返されます。同じドメイン ポリシーが適用され、JSONP などの回避策があることは理解していますが、HTML フォーム全体を返す方法がわかりません。
現在、localhost でテストしているので、サーバー上の別のページに GET を使用するだけで、同じドメイン ポリシーについて心配する必要がなくなります。
これが私の思考プロセスです。
//form_deliver.php
//this code would go on the customer's server which would then call to mine
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
<?php
echo "look at all of this stuff!";
?>
<script>
$.getJSON("/form_deliverer.php?form_request=true",function(data) {
//alert(data.check); //this was just for testing,
});
</script>
GETリクエストを送信するページは次のとおりです
//form_deliverer.php
//this code is on my server which will return a form to the customer
<?
if(isset($_GET['form_request'])){
// echo json_encode(array("check" => "true")); //just for testing
//return form here
?>
簡単にするために、これが私が返したいフォームだとしましょう
<form method="post">
<input type="textbox" name="text"/>
<input type="submit" name="submit_text"/>
</form>
編集これはjackJoeの提案による私の更新です
form_deliver.php のコード
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
<?php
echo "look at all of this stuff";
?>
<script>
var form_request = "true";
$.get("/form_deliverer.php", {var: form_request},
function(data){
$("#yourdiv").html(data);
}, "html");
</script>
<div id = "yourdiv">
</div>
これは form_deliverer.php にあります
<?
if(isset($_GET['form_request'])){
return "
<form method='post'>
<input type='textbox' name='text'/>
<input type='submit' name='submit_text'/>
</form>
";
}
?>