Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net/jQuery: post data with jQuery to a popup [IE]

I'm trying to post data with jQuery in an asp.net application to a popup.

If the popup opens, I'm getting three errors. The first error is:

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

(error code [code is in popup site]:http://www.suckmypic.net/26449/e65f2d77.png, orig. code [code is in popup site]:http://www.suckmypic.net/26450/7dfdf013.png)

then I'm getting two errors of private functions which are included correctly.

Then - if I'm reloading the popup window, everything is working fine.

I open the popup in this way:

$.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's stored in a function that I'm calling on pressing the f1 key which is working fine)

I'm referencing in the mainpage and in the popup window all my functions and the jquery library.

Edit

The code for the 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, basing on window size)

If I change it simply 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);

Another Edit: Just tried chrome and firefox - no error there. But I need the code to work with IE.

like image 572
Keith L. Avatar asked Feb 03 '12 15:02

Keith L.


4 Answers

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

$.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);
});
like image 63
ShankarSangoli Avatar answered Oct 18 '22 20:10

ShankarSangoli


First of all thanks for the replies.

I've tried every answer, but I'm still always get the errors in internet explorer.

I've found a workaround, but it does not make me happy because i think generating a new form with input fields is too much for my needs.

Since it's the only working option for posting my data into a popup without getting the jQuery error, I've 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);

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

like image 27
Keith L. Avatar answered Oct 18 '22 20:10

Keith L.


I guess jquery library are getting loaded on both pages.

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

$.post shorthand function for $.ajax , so it works as asynchronous . I suggest to make it synchronous if possible.

like image 1
Rohit Avatar answered Oct 18 '22 20:10

Rohit


try this:

$.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'
});
like image 1
andres descalzo Avatar answered Oct 18 '22 21:10

andres descalzo