2010-12-19 16 views
3

こんにちは:)私はjqueryスクリプトでajax経由でいくつかのコンテンツを取得する方法を理解しようとしています。私のニーズに合うようにこのスクリプトをカスタマイズしようとしています。ajaxを使用してモーダルポップアップでPHPを表示する方法

$('a.poplight[href^=#]').click(function() { 
var popID = $(this).attr('rel'); //Get Popup Name 
var popURL = $(this).attr('href'); //Get Popup href to define size 

//Pull Query & Variables from href URL 
var query= popURL.split('?'); 
var dim= query[1].split('&'); 
var popWidth = dim[0].split('=')[1]; //Gets the first query string value 

//Fade in the Popup and add close button 
jQuery('#' + popID).fadeIn(200).css({ 'width': Number(popWidth) }); 


//Define margin for center alignment (vertical horizontal) - we add 80px to the height/width to accomodate for the padding 
var popMargTop = ($('#' + popID).height() + 80)/2; 
var popMargLeft = ($('#' + popID).width() + 80)/2; 

//Apply Margin to Popup 
jQuery('#' + popID).css({ 
    'margin-top' : -popMargTop, 
    'margin-left' : -popMargLeft 
}); 

//Fade in Background 
$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag. 
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) IE 

return false; 


}); 

//Close Popups and Fade Layer 
$('a.close, #fade, .cancel').live('click', function() { //When clicking on the close or fade layer... 
    $('#fade , .popup_block').fadeOut(function() { 
     $('#fade, a.close').remove(); //fade them both out 
     $('form').clearForm(); 
}); 
    return false; 
}); 

これは非表示のdivです。私はちょうど代わりにすべての内容を保持するPHPファイルを呼び出すようにwoukd。これはhtmlのようなものです:

<a href="#?w=480" rel="whatever" class="poplight"><input type="button" class="button" value="update"/></a> 

アイデア?おかげで事前に:)

[OK]を、私はjQueryのUIのダイアログを試してみました...と私は言わなければならない、それはちょっとイライラ... 私はそれが誰かよそコーディングをたどるのは難しいけど、私は実際にはほとんどすべてを微調整することができますHREFが戻ってこれまでそうイム任意の実際のコンテンツ

モーダルサイズを呼び出し、およびされていないので、そうしないのはなぜ笑データをフェッチし、ポップでそれを表示するには

答えて

2

をこのコードを使用する方法を除きます代わりにjquery uiのmodal dialogを使用してください(良いコード品質)。その後、コンテンツを取得$.get()

+0

面白いことは、ええ、私はできます。私はすでにいくつかの他の使用のためにGoogleを介してライブラリをロードしています。私は1つの石で2羽の鳥を殺すことができました。私はまだ$ .get()を使用することに慣れていなければなりませんが、私にそのことを思い出させることに感謝します:P – Sin

+0

$ .getには、あなたを始めるための十分な例があります。 $ .get()を使うのはとても簡単です! – Alfred

+0

@シン、私はあなたの質問に答えるだろうが、あなたはすでにjQueryUIをロードしているので、それを使用する方が良いです、upvoted。 – ifaour

関連する問題