2012-02-03 42 views
6

我正試圖在jQuery中將數據發佈到一個asp.net應用程序中,以便彈出窗口。asp.net/jQuery:使用jQuery將數據發佈到彈出窗口[IE]

如果彈出窗口打開,我得到三個錯誤。 第一個錯誤是:

Errror: the value of the property is null or undefined not a function object 

(錯誤代碼[代碼是在彈出站點]:HTTP://www.suckmypic.net/26449/e65f2d77.png, 原稿代碼[代碼是在彈出網站]:http://www.suckmypic.net/26450/7dfdf013.png)

然後我得到two errors私人功能,包括正確。

然後 - 如果我是重新加載彈出窗口,一切工作正常。

我用這種方式打開彈出:

$.post('popup.aspx', { X: $("#X1").val(), XX: varX, XXX: varXY, Z: varZ}, function (result) { 

    hWndHelp = window.open('', 'help', cStyle); 
    hWndHelp.focus(); 
    hWndHelp.document.open(); 
    hWndHelp.document.write(result); 
    hWndHelp.document.close(); 
}); 

(它存儲在我號召的壓榨工作正常F1鍵的功能)

我在主頁面和彈出窗口中引用我所有的函數和jQuery庫。

編輯

cStyle VAR的代碼:

var WIN_STYLE_RESIZE = 
    'resizable = yes, ' + 
    'status = yes, ' + 
    'scrollbars = yes'; 

var cStyle = 
     WIN_STYLE_RESIZE + ', ' + 
     'width = ' + w + ', ' + 
     'height = ' + h + ', ' + 
     'top = ' + y + ', ' + 
     'left = ' + x; 

(W,H,Y,X計算的數字,對窗口大小基礎)

如果我只需將其更改爲'width=600,height=400',錯誤仍然會發生。

如果我通過get發送我的變量它也可以,但我需要隱藏URL中的變量。

工作 get方法:

var getUrl = "popup.aspx?X="+$('#X1').val()+"&...."; 
hWndHelp = window.open(getUrl, 'help', cStyle); 

另一個編輯: 剛纔試了Chrome和Firefox - 任何的錯誤。但我需要代碼與IE一起使用。

+0

在女巫線你會得到第一個錯誤? – Aristos 2012-02-03 15:11:13

+0

第2行(第1行爲空) – 2012-02-03 15:12:27

+0

我遺失了你,你能指出這段代碼嗎? – Aristos 2012-02-03 15:14:21

回答

2

第一。

我試過每個答案,但我仍然總是得到在Internet Explorer中的錯誤。

我找到了解決方法,但它並沒有讓我開心,因爲我認爲生成一個帶有輸入字段的新窗體對於我的需求來說太多了。

因爲它是將數據發佈到彈出窗口而不會出現jQuery錯誤的唯一工作選項,所以我決定使用它。

var form = document.createElement("form"); 
form.setAttribute("method", "post"); 
form.setAttribute("action", "popup.aspx"); 
form.setAttribute("target", "help"); 

var input = document.createElement("input"); 
input.type = "hidden"; 
input.name = "X"; 
input.value = $("#X").val(); 
form.appendChild(input); 

var input2 = document.createElement("input"); 
input2.type = "hidden"; 
input2.name = "XX"; 
input2.value = varX; 
form.appendChild(input2); 

var input3 = document.createElement("input"); 
input3.type = "hidden"; 
input3.name = "XXX"; 
input3.value = varXY; 
form.appendChild(input3); 

var input4 = document.createElement("input"); 
input4.type = "hidden"; 
input4.name = "Z"; 
input4.value = varZ; 
form.appendChild(input4); 

document.body.appendChild(form); 

hWndHelp = window.open("about:blank", "help", cStyle); 
hWndHelp.focus(); 

form.submit(); 
document.body.removeChild(form); 

原始出處: http://taswar.zeytinsoft.com/2010/07/08/javascript-http-post-data-to-new-window-or-pop-up/

2

在訪問之前花點時間打開window。嘗試這個。

$.post('popup.aspx', { X: $("#X1").val(), XX: varX, XXX: varXY, Z: varZ}, function (result) { 

    var hWndHelp = window.open('', 'help', cStyle); 
    setTimeout(function(){ 
    hWndHelp.focus(); 
    hWndHelp.document.open(); 
    hWndHelp.document.write(result); 
    hWndHelp.document.close(); 
    }, 400); 
}); 
+0

它不會刪除我的錯誤:( – 2012-02-06 08:09:20

0

看起來你在popup.aspx中缺少jQuery。確保它包括在內。

+0

請閱讀傳出後更加小心 – 2012-02-06 12:24:09

1

我想jQuery庫正在加載在這兩個頁面上。

,你也已經包括$。員額在$(函數(){} .......爲$

$。員額速記功能。ajax,所以它的工作方式是異步的。 如果可能,我建議讓它同步。

+0

所以,你會怎麼做, 我想:? 功能myFunction的(){ '$(「#myForm的」)提交(函數(){0;} {0;} {0;}';'('#myForm')。submit() ); }' 當我按下'F1'(我按照我所描述的方式調用我的函數)時,會打開一個窗口,但在下一秒重新加載主頁面 – 2012-02-06 12:20:35

+0

改爲使用$ .ajax $ .post http://api.jquery.com/jQuery.post/ – Rohit 2012-02-06 13:00:04

1

嘗試這個辦法:所有感謝的答覆

$.ajax({ 
    type: 'POST', 
    url: 'popup.aspx', 
    data: { X: $("#X1").val(), XX: varX, XXX: varXY, Z: varZ}, 
    success: function(data, textStatus, jqXHR) { 

    var hWndHelp = window.open('about:blank', 'help', cStyle); 

    hWndHelp.focus(); 
    hWndHelp.document.open(); 
    hWndHelp.document.write(data); 
    hWndHelp.document.close(); 

    }, 
    dataType: 'html' 
}); 
1

我做了一個jQuery插件來做到這一點。不一定是jQuery,但我的是。

(function ($) { 
    $.submitFormToPopup = function (action, params, target, windowOpts) { 
     var formID = 'submitFormToPopup'; 
     var form = $('<form />') 
      .attr('method', 'post') 
      .attr('action', action) 
      .attr('target', target) 
      .attr('id', formID); 
     $.each(params, function (key, value) { 
      form.append($('<input />') 
       .attr('type', 'hidden') 
       .attr('name', key) 
       .attr('value', value)); 
     }); 
     $(document.body).append(form); 
     window.open('about:blank', target, windowOpts); 
     form.submit(); 
     $(document.body).remove('#' + formID); 
    }; 
})(jQuery); 
相關問題