Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to post form data to a new window using jQuery/AJAX?

Tags:

One of the pages in my application has a set of links that when clicked, posts form data based on the TableTools jQuery plugin. I'd like this new page to open up in a new window. Any ideas on the best way to do this? I'd rather not change all of my action links over to individual forms and use target="_blank". I've tried calling a new window to open on success, and posting writing the data to this page, but that hasn't been working. Please help!

HTML:

<div id="action">                        
    Download
</div>   

Javascript:

$('#action').click( function () { 

    var userData = oTable.fnGetColumnData(0);

    $.ajax({
        type: "POST", 
        url: "../download.php",
        data: "user_list=" + userData,
        dataType: "json",
        success: function(data){
            var win = window.open();
            win.document.write(data);
        }
    })  

})
like image 717
Michael Avatar asked Jan 18 '12 23:01

Michael


People also ask

How can we POST using jQuery to a form?

Answer: Use the jQuery submit() Method You can use the submit() method to submit an HTML form (i.e. <form> ) using jQuery. The jQuery code in the following example will submit the form on click of the button (i.e. the <button> element) which has the type attribute set to button (i.e. type="button" ).

How can add multiple form data using jQuery AJAX?

For Sending or inserting or saving multiple data in single click then you have to use Jquery and javascript code. By using Jquery or Javascript code you can generate dynamic HTML field in your HTML form. We can generate any dynamic HTML field by using Jquery and append into your form fields.


1 Answers

Found the answer:

jQuery.ajax success callback function not executed

When I took out the dataType: "json", it worked!

like image 91
Michael Avatar answered Oct 15 '22 15:10

Michael