2010-11-24 9 views
0

私は何をjqueryにプロトタイプに変換しようとしています。ajaxの投稿結果でjqueryを更新する

私のプロトタイプは、jQueryのに上記の変更方法

$$(".user-link").each(function(el){ 
el.observe("mouseover", function(event) { 
    _selectedLinkEl = el; 
    _detailEl = event.element().next(); 
    _detailEl.show(); 
    _href=el.readAttribute('href').split("/")[2]; 

     new Ajax.Request('/users/user_detail/?name='+_href, { 
    onSuccess: function(transport) { 
     if (200 == transport.status) 
      _detailEl.update(transport.responseText); 
     } 
            }); 

    _body.observe("mouseover", _bodyMouseOverFunction); 
}); 
}); 

    var _bodyMouseOverFunction = function(event) { 
if(event.element() != _selectedLinkEl && 
     event.element() != _detailEl && 
     !event.element().ancestors().include(_detailEl)) { 
_detailEl.hide(); 
_body.stopObserving("mouseover", _bodyMouseOverFunction); 
    } 
}; 

のですか?

user-linkは、多くのリンクに存在するクラス名です。このリンク上でマウスでajaxリクエストを実行しようとしています。

EDIT:

私は私が更新するために、どのようにAJAXリクエストの結果とアラートを取得しています jQueryのよう(ドキュメント).ready(関数(){

    jQuery(".user-link").hover(function() { 


         jQuery(this).next().show(); 
      var href=jQuery(this).attr("href"); 

      href= href.split("/")[2]; 

     jQuery.post('http://localhost:3000/users/user_detail/?name='+href, 
     function(data){ 
      alert("Data Loaded: " + data); 

      } 

      ); 


     }); //hover 
    });// doc ready 

を試してみました。結果の要素がうまくいけば、これはあなたが始めるのに役立つだろう??

+0

1. jqueryを学ぶ2.プロトタイプを学ぶ3. – mkoryak

答えて

1

を得た:

$(".user-link").mouseover(function(event) { 
    _selectedLinkEl = this; 
    _detailEl = event.target.next(); 
    _detailEl.show(); 
    _href=$(this).attr('href').split("/")[2]; 

    $.get('/users/user_detail/?name='+_href, 
     function(data, textStatus, xhr) { 
     if (200 == xhr.status) { 
      _detailEl.text(textStatus); 
     } 
     } 
    ); 

    $(_body).mouseover(_bodyMouseOverFunction); 
}); // user-link 

var _bodyMouseOverFunction = function(event) { 
    if(event.target != _selectedLinkEl && 
     event.target != _detailEl && 
     $.inArray(_detailEl, event.target.parents()) == -1) { 
     _detailEl.hide(); 
     $(_body).unbind("mouseover", _bodyMouseOverFunction); 
    } 
}; 
+0

が更新されていない。 – useranon

+0

私はその行を逃した。 text()に置き換えられました。 –

+0

xhrが定義されていないため、エラーが表示されます。 – useranon

関連する問題