Asp.net/jQuery: send data using jQuery to popup [IE]

I am trying to send data using jQuery in an asp.net application to a popup.

If the popup opens, I get three errors. First mistake:

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

(error code [code is on the pop-up site]: http://www.suckmypic.net/26449/e65f2d77.png, original code [code is on the pop-up site]: http://www.suckmypic.net/26450/ 7dfdf013.png)

then I get two errors private functions that are included correctly.

Then - if I reload the popup, everything works fine.

I open a popup as follows:

 $.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(); }); 

(it is stored in the function that I call when I press f1, which works fine)

I link to the main page and in the popup window all my functions and the jquery library.

Edit

Code for 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 are calculated numbers based on window size)

If I change it just to 'width=600,height=400' , the error still occurs.

If I send my variables via get , it also works, but I need to hide the variables in the URL.

Working get method:

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

Other Editing: Just tried chrome and firefox - no errors there. But I need code to work with IE .

+6
source share
6 answers

First of all, thanks for the answers.

I tried every answer, but I still always get errors in Internet Explorer.

I found a workaround, but that does not make me happy, because I think that creating a new form with input fields is too much for my needs.

Since this is the only working option for placing my data in a popup without receiving a jQuery error, I decided to use it.

 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); 

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

+2
source

Give some time to open the window before accessing it. Try it.

 $.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); }); 
+2
source

I think the jquery library is loading on both pages.

And also you included $ .post in $ (function () {.......}

$. post shortens the function for $ .ajax, so it works as asynchronous. I suggest doing it synchronously, if possible.

+1
source

try the following:

 $.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
source

I made a jQuery plugin for this. It doesn't have to be jQuery, but mine.

 (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); 
+1
source

It looks like you are missing jQuery in popup.aspx. Make sure it is turned on.

0
source

Source: https://habr.com/ru/post/907579/


All Articles