views:

61

answers:

3

Hi Guys,

I have a script that on.DocumentReady posts data to another page. That page responds with some HTML encapsulated in one div tag.

My goal is to have this post response/data open in a new window.

Any hints or clues?

Here is the snippet I created from Dr. Mille's advice.

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"&gt;&lt;/script&gt;
 <script type="text/javascript">
$(document).ready(function() {
var packslip_id = 35592;
var po_no = 0018439;
var  box_no = 1;
    $.post("https://example.com/barcode/generate", { packing_slip: packslip_id, reference: po_no, total_boxes: box_no}, 
    function (data) {
        alert(data);
        var win=window.open('about:blank');
        with(win.document)
        {
            open();
            write(data);
            close();
        }
    });
 });

A: 

try

$.post('urpage.php',{},
function(data) {
window.open('page.php?data=data')
});

and have page.php show whatever data was supposed to be

Ascherer
The page that I am posting to returns the html that I want to open in a new window... having to send it to another page seems like doing it twice...
Peter
have the page u are sending it to, just send the data. otherwise im not sure if u can pass html to window.open, tho a google search would tell you quickly if thats possible.
Ascherer
+2  A: 

Use the write()-Method of the Popup's document to put your markup there:

$.post(url, function (data) {
var win=window.open('about:blank');
with(win.document)
{
  open();
  write(data);
  close();
}

});

Dr.Molle
I think I am using what you are saying correctly..., but its not opening a popup or actually posting any data to the server. I put the new code in the in the original post.
Peter
The use looks correct. You are using an absolute URL, whats's the reason?
Dr.Molle
The url is on a separate server. I got it working now when I run it on my local mamp installation and using "Coda's" Preview function... but when I run it through safari, no data is coming up at all... I am sooo confused now. Thanks for all your help so far.
Peter
AJAX-Requests only work on the same Domain. Would it be an oportunity to do the thing without AJAX?
Dr.Molle
What would you use?
Peter
I am just gonna move the scripts onto that server... But I am really interested in knowing what you would use other than ajax... and Thanks for all your help!
Peter
See the example beyond, it will open the Popup and show the data without AJAX. It simply submit's the form directly into the popup which will be created before.
Dr.Molle
A: 

If you dont need a feedback about the requested data and also dont need any interactivity between the opener and the popup, you can post a hidden form into the popup:

Example:

<form method="post" target="popup" id="formID" style="display:none" action="https://example.com/barcode/generate" >
  <input type="hidden" name="packing_slip" value="35592" />
  <input type="hidden" name="reference" value="0018439" />
  <input type="hidden" name="total_boxes" value="1" />
</form>
<script type="text/javascript">
window.open('about:blank','popup','width=300,height=200')
document.getElementById('formID').submit();
</script>

Otherwise you could use jsonp. But this works only, if you have access to the other Server, because you have to modify the response.

Dr.Molle