Can the AJAX URL be loaded onto a new page?

https://i.stack.imgur.com/5l63v.pngPardon the poorly phrased question, but I need some guidance on a specific requirement regarding opening a URL in a new page. Currently, I have designed an AJAX URL and I'm wondering if it's possible to open this AJAX URL in a new page like a regular URL. Otherwise, I may need to make extensive changes to the code provided below:

  function pdfPrint(start_date , end_date , view){

    var startDate = $('#setDate-'+start_date).val();
    var endDate = $('#setDate-'+end_date).val();       
    data = {
            "startDate":startDate,
            "endDate":endDate,
            "view":view,
            "systemid":system_id,
        };
    $.ajax({
        url: "{{route('download.pdf')}}",
        type: "get",
        'headers': {
          'X-CSRF-TOKEN': '{{ csrf_token() }}'
        },
        data:data,
    }).done(downloadFile);       
}

Answer №1

Discover this easy method for opening a window and executing JavaScript code:

let js = `<script>
    function pdfPrint() {
        window.print();
    }
    
    // Execute your custom function
    pdfPrint();</` + `script>`;

let win = window.open("", "MsgWindow", "width=400,height=400");
win.document.write(js);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Theme's functions.php file can utilize AJAX action for dynamic loading

After some investigation, it seems that the wp_ajax_my_action function is only functional when placed within a plugin. I'm curious if there's a way to make it work directly in my theme's functions.php file. Any ideas? ...

Updating and submitting data with Ajax using the `h:commandButton` component

Is there a way to update a div and achieve partial submission with the <h:commandButton> element? In the past, I utilized the <p:commandButton> for partial submission by setting the ajax attribute to true and updating the :statusBlock. Howeve ...

No Angularjs redirection without the "onload" event

In my search for a solution, I came across this answer but it did not quite fit my needs: Pass onload event through redirect The issue I'm facing is that I want the AngularJS section of my application to reload something when the user is redirected ...

Creating a personalized search form in Magento admin area

I want to incorporate a personalized Ajax search form into the Magento admin section under "Customer Information" => "Orders". The search should be able to find items based on their id, sku, and product names. What steps do I need to take in order to achi ...

Encountering a ReferenceError stating that the window object is not defined while building a React Leaflet application

In my upcoming nextjs project, I've incorporated react-leaflet. It behaves flawlessly in dev mode. However, upon attempting to build the project, it throws a ReferenceError: window is not defined. Despite setting ssr to false in dynamic, the error per ...

Leveraging Greasemonkey along with jQuery to capture and manipulate JSON/AJAX data on a webpage

In my previous inquiry on Stack Overflow, I received some insight into my issue regarding Greasemonkey interpreting jQuery. However, the challenge remains in directing GM to retrieve data from a specific location and place it into an array. When visiting ...

Verify the checkbox for validation is shown exclusively

I am currently facing an issue with a form that includes a checkbox, which is only displayed under certain conditions. I want to ensure that the checkbox is checked only when it is visible, and if not, the form should be submitted upon clicking the submit ...

Running AngularJS controllers should only occur once the initialization process has been fully completed

I am facing a situation where I need to load some essential global data before any controller is triggered in my AngularJS application. This essentially means resolving dependencies on a global level within AngularJS. As an example, let's consider a ...

Using jQuery to create clickable images by enclosing them in an `<a>` tag

How can I make each image with a specific class clickable? I would like jQuery to: Retrieve the src attribute of the image. Enclose the image within an a href tag that includes that src URL. .clickable { padding: 20px; border: 1px ...

Evaluating substrings within a separate string using JavaScript

I need to compare two strings to see if one is a substring of the other. Below are the code snippets: var string1 = "www.google.com , www.yahoo.com , www.msn.com, in.news.yahoo.com"; var string2 = "in.news.yahoo.com/huffington-post-removes-sonia-gandh ...

Node.js Export Module Error - importance of separating concerns

I have been attempting to implement separation of concerns by using export module. Everything functions properly when used without separating concerns, but as soon as I try to import generateUrlArray() from const db = require('../db'), nothing se ...

Is it possible for the upload form submission to wait until the file processing is finished?

Is it possible for the form submission to wait until the file processing is complete? I am currently using web2py and its sqlform to upload a video file. As the file is being uploaded, it is also being converted to flv format. The progress of both uploadi ...

Enhancing SVG graphics dynamically with JavaScript and ensuring compatibility across different web browsers

I am currently working on incorporating an element into an existing SVG file. Interestingly, the process runs smoothly on Chrome and Firefox but encounters issues on Edge. I aim for it to function seamlessly on the latest versions of all three browsers, wi ...

Sending back numerous information in the catch block

Recently, I was testing out the fetch API and encountered an issue with logging a fetch error. I tried catching the error and logging it within the catch block. Strangely, even when I added additional console.log statements in the catch block, they would ...

What is the best way to incorporate a function within a $.click (jquery) event that utilizes an id directly from the clicked element?

It seems that my title may not be very clear, but I have a jQuery code snippet that is causing some issues. The problem stems from the fact that when I click on an image with the class 'slideimg', I expect a function named slideDo to be executed, ...

Ways to import a library in JavaScript/TypeScript on a web browser?

I'm currently working on a project that involves a TypeScript file and an HTML page. Right now, I am loading the necessary libraries for the TypeScript file in the HTML Page using script tags like <script src="https://unpkg.com/<a href="/cd ...

In search of a render function that can effectively apply styles to HTML strings using React JS

I have been struggling to convert the result field value, including HTML attributes string, into respective styles for one column in my antd table. Below is the string I am trying to convert: The exhaust air requirements for fume hoods will be based on m ...

Encountering issues with React Apollo hooks after integrating React Native into the monorepo system

I am in the process of setting up a React web app and a React-native app within a monorepo using yarn workspaces. The web and controllers are functioning properly, allowing me to successfully execute graphql queries to my apollo-express server. However, up ...

What could be causing my textarea-filling function to only be successful on the initial attempt?

Programming: function updateText() { $("body").on("click", ".update_text", function(event) { $(this).closest("form").find("textarea").text("updated text"); event.preventDefault(); }); } $(document).ready(function() { updateText(); }); H ...

Jquery Ajax is failing to transmit the authorization header

Attempting to set up basic authentication using Jquery Ajax. Adding an authorization header to the ajax request as shown below. $.ajax({ headers: { "authorization": "basic 123456", }, crossDomain: true, type: "POST", contentTyp ...