2012-10-13 75 views
0

Jquery的盒子,我想用加載Twitter的彈出框的jQuery(阿賈克斯?)加載Twitter的盒子通過Ajax

這裏是我的原代碼,它加載Twitter的框在一個新的窗口:

function twitter_click() { 
    var twtTitle = document.title; 
    var twtUrl = location.href; 
    var maxLength = 140 - (twtUrl.length + 1); 
    if (twtTitle.length > maxLength) { 
     twtTitle = twtTitle.substr(0, (maxLength - 3)) + '...'; 
    } 
    var twtLink = 'http://twitter.com/home?status=' + encodeURIComponent(twtTitle + ' ' + twtUrl); 
    window.open(twtLink,'','width=565, height=540'); 
} 

這裏是jquery彈出框的代碼。

function showUrlInDialog(url, options){ 
    options = options || {}; 
    var tag = $("<div></div>"); //This tag will the hold the dialog content. 
    $.ajax({ 
    url: url, 
    type: (options.type || 'GET'), 
    beforeSend: options.beforeSend, 
    error: options.error, 
    complete: options.complete, 
    success: function(data, textStatus, jqXHR) { 
     if(typeof data == "object" && data.html) { //response is assumed to be JSON 
     tag.html(data.html).dialog({modal: options.modal, title: data.title}).dialog('open'); 
     } else { //response is assumed to be HTML 
     tag.html(data).dialog({modal: options.modal, title: options.title}).dialog('open'); 
     } 
     $.isFunction(options.success) && (options.success)(data, textStatus, jqXHR); 
    } 
    }); 
} 


<a href="#" onclick="showUrlInDialog('/feedback-form', {error: function() { alert('Could not load form') }}); return false;"><img src="twitter_button.jpg></a> 

我不知道編碼,所以如果有人能請結合這兩個腳本什麼讓第一個腳本加載的內容嘰嘰喳喳到jQuery的彈出腳本,將讓我的天!謝謝。皮婭

回答

0

開始通過改變這樣的:

window.open(twtLink,'','width=565, height=540'); 

這樣:

showUrlInDialog(twtLink, {error: function() { alert('Could not load form') }}); 

然後運行它,使用:

<a href="#" onclick="twitter_click()"><img src="twitter_button.jpg></a>