0

GETフォームの結果ページをdivにターゲットにする方法を探しています。これまでのところ、ほとんどのソリューションでは代わりに Iframe を使用するように指示されていましたが、私の目的は結果ページに何らかの変更を加えることであり、Iframe を使用するとクロス ドメイン スクリプティング ルールがアクティブになり、ページ コンテンツを取得できなくなります。

結果ページは通常、未加工の XML です。

<html>
<head>
<link rel="stylesheet" href="css/smoothness/jquery-ui-1.9.2.custom.css" >
<script src="js/jquery-1.8.3.js"></script>
<script src="js/jquery-ui-1.9.2.custom.js"></script>
<script src="js/jquery.xslt.js"></script>
<script type="text/javascript">

$(function() {
    var xmlContent = $("#CFrame").contents().find("*").text();

    $('#SResult').xslt({xml:xmlContent, xslUrl:'stylesheet/styleSheet.xsl'});
});

// prepare the form when the DOM is ready 
function submitForm() { 
    // bind form using ajaxForm 
    $('#searchForm').ajaxForm({ 
        // dataType identifies the expected content type of the server response 
        dataType:  'xml', 
        // success identifies the function to invoke when the server response 
        // has been received 
        success:   processXml
    });
    return false; 
}

function processXml(responseXML) { 
    // 'responseXML' is the XML document returned by the server; we use 
    // jQuery to extract the content of the message node from the XML doc 
    var message = $(responseXML).text(); 
    $("#SResult").text(message); 
}
</head>
<body>
   <form id="searchForm" method="GET" action="http://111.11.111.11:1111/search" onSubmit="submitForm()">
     <!--.... Some input go here-->
    <input type="submit" value="Search" />
<div id="SResult">
</div>
<iframe id="CFrame" name="ContentFrame" frameborder="1" height="1000px" width="1000px" scrolling="no"></iframe>
</body>
<script>
loadUI();
</script>
</html> 

ありがとう、

4

3 に答える 3

0

jsonp、サーバー プロキシを使用するか、他のドメインを制御しない限り、別のドメインに対して get または post 要求を行うことはできません。ajax 呼び出しを行っているドメインを制御できる場合Access-Control-Allow-Originは、要求しようとしているページに応答ヘッダーを追加して、ドメイン アクセスを許可することができます。

XML を返す GET リクエストを実行しているので、YQL をプロキシとして使用するこの jQuery プラグインを使用することをお勧めします。また、このガイドを使用して、それがどのように機能するかを確認したり、プラグインなしで実行したりできます.

この同じ問題に対処する解決済みのスタック オーバーフローの質問: jQuery を使用したクロス ドメイン リクエスト

于 2013-01-07T05:35:43.170 に答える
0

get メソッドを使用してフォームを送信すると、応答が div タグに表示されますか?

Jquery ajax を使用できます。

$.ajax({
   type: "POST",
   url: "url here",
   data: {id: someIdTobePass},
   success: function(response){
      //do the jquery manipulation
      $("#myDivID").html("the response is " + response);
   }
});
于 2013-01-07T03:15:09.580 に答える
0

jQuery で$.getヘルパー メソッドを使用できます。

jQuery API

jQuery.get( url [, データ ] [, 成功 (データ, テキストステータス, jqXHR) ] [, データタイプ] );

コードサンプル

$.get("test.php", { name: "John", time: "2pm" },function(data){
   $("#mydiv").html(data);
});
于 2013-01-07T04:54:26.823 に答える