2010-11-29 9 views
1

私は、Solrをベースにした検索サービスを作成して、clipというオブジェクトのデータベースを索引付けしました。検索サービスは、OpenSearchアトム拡張形式を使用してフォーマットされた検索結果を返します。クリップにはさまざまなプロパティがあり、クリップIDとタイトルは私の質問に関連する2つのプロパティです。JQueryを使用して、IE 8で "Title"というXML要素のテキスト値を抽出します。

jqueryを使用して非常に簡単なJavaScriptプログラムを作成しました。jqueryは、バックグラウンドで検索サービスを非同期で呼び出し、ClipIdとTitle値を持つテーブルにデータを設定します。このプログラムはChrome、Safari、FFで正常に動作します。しかし、IEでは、単にTitle属性の値を解析できません。これは、 "Title"が予約されたXMLタグ名で、IEのjQueryがそれを見つけることができないかのようです。ここで

は私のJavaScriptプログラムからの抜粋です:

// Ajax call to the search service over HTTP. 
    var doSearch = function(){ 
    var query = "Title:" + $("#searchQuery").val() + "*"; 

    $.ajax({ 
     url : "/quantel/search/select" , 
     data:{q:query}, 
     error:function(request,status,error){ 
     alert(request + "," + status + "," + error); 
     }, 
     dataType: "text/xml", 
     success:function(data,status,request){ 
     // Clear the data table. 
     $("#searchResults").dataTable().fnClearTable(); 
     // Search for all clip entries in the XML document. 
     $(data).find("entry").children("content").each(function(index,element) { 

     var clipID= $(element).children("ClipID").text(); 
     var title = $(element).children("Title").text(); 

     // Add the clip id and title to the table. 
     $("#searchResults").dataTable().fnAddData([clipID,title]); 
     });  
     } 
    }); 
    }; 

そして、ここでは、私が解析しようとしている検索結果のサンプルです。あなたが見ることができるように、ContentタグはTitleタグを含んでいますが、IEはそれを見つけることができません。

<?xml version="1.0" encoding="UTF-8"?> 
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"> 
<title>ProjectFolders Search</title> 
<link href="http://localhost:8182/quantel/search/select?q=guillaume*&amp;rows=100&amp;" /> 
<link rel="self" href="http://localhost:8182/quantel/search/select?q=guillaume*&amp;rows=100&amp;" /> 
<link rel="first" href="http://localhost:8182/quantel/search/select?q=guillaume*&amp;rows=100&amp;start=0" /> 
<link rel="last" href="http://localhost:8182/quantel/search/select?q=guillaume*&amp;rows=100&amp;start=0" /> 
<link rel="previous" href="http://localhost:8182/quantel/search/select?q=guillaume*&amp;rows=100&amp;start=0" /> 
<link rel="next" href="http://localhost:8182/quantel/search/select?q=guillaume*&amp;rows=100&amp;start=0" /> 
<updated>2010-11-29T14:45:53.796Z</updated> 
<author> 
    <name>Quantel</name> 
</author> 
<id>urn:uuid:cd9d3362-2159-4c27-a99e-9691dd4ff707</id> 
<opensearch:totalResults>6</opensearch:totalResults> 
<opensearch:startIndex>0</opensearch:startIndex> 
<opensearch:itemsPerPage>100</opensearch:itemsPerPage> 
<entry> 
    <title type="html">Guillaume_clip</title> 
    <updated>2010-10-25T11:10:17.000+01:00</updated> 
    <id>urn:clipid:389685</id> 
    <link href="http://localhost:8182/quantel/search/select?q=ClipID:389685" /> 
    <content type="text/xml"> 
    <PlaceHolder>0</PlaceHolder> 
    <HasEditData>0</HasEditData> 
    <id>389685</id> 
    <ClipID>389685</ClipID> 
    <Created>2010-10-25T11:10:17.000+01:00</Created> 
    <NumVidTracks>0</NumVidTracks> 
    <CloneZone>119</CloneZone> 
    <MosActive>0</MosActive> 
    <Template>0</Template> 
    <Completed>2010-10-25T11:10:18.000+01:00</Completed> 
    <Frames>0</Frames> 
    <Title>Guillaume_clip</Title> 
    <UnEdited>1</UnEdited> 
    <ClipGUID>7e5aef9c7da44bacbfb49500710138cf</ClipGUID> 
    <CloneID>389685</CloneID> 
    <NumAudTracks>0</NumAudTracks> 
    </content> 
</entry> 
</feed> 
+0

「ClipID」の行は機能しますか? (また、 'var title = element.getElementsByTagName(" Title ")[0];'を試すことができますか?) – Tomalak

+0

$ .ajax呼び出しの 'dataType'オプションに無効な値があります。 'xml'にする必要があります。 http://api.jquery.com/jQuery.ajax/ – thorn

+0

ClipIDの行が機能します。実際には、タイトル以外のすべてのフィールドを取得しようとすると動作します。私はvar title = element.getElementsByTagName( "Title")[0] .textを試しました。これはChromeでは動作しますが、IEでは動作しません。 –

答えて

3

dataTypeオプションの$.ajaxコールの値が無効です。 xmlである必要があります。 http://api.jquery.com/jQuery.ajax

無効なデータ型の場合、IEはコンテンツをHTMLとして解析するため、title要素はhead要素に移動されます。

また、応答のMIMEタイプはtext/xmlである必要があります。他のMIMEタイプを保持する必要がある場合は、ここに記載されている方法でXMLレスポンスを解析できます:http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests

+0

タイトルの要素についての説明をありがとうヘッド要素に移動します。意味あり。しかし、私が$ .ajaxのdataTypeをxmlに設定すると、動作しないので、解析エラーが発生します。私はIEから直接それを読むことができるようにXMLがうまく形成されていると確信しています、そして、それは文句を言っていません。私は当初$ .ajaxのショートカットとして$ .getを使用していましたが、動作しませんでした。 –

+0

サーバーはこのコンテンツ(text/xml)に正しいMIMEタイプを返しますか? – thorn

+0

このタイプのコンテンツの正しいMIMEタイプはapplication/atom + xmlです –

0

タイトルは別の名前空間にする必要があります。あなたは試してみることができます

$(elment).find( 'アトム\:タイトル')。

iPadでは、今すぐ試用できません。

関連する問題