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

You cannot nest a map function within another map function in React

Having some trouble applying the map function in HTML using React. Below is the code snippet: response = [ data : { name: 'john', title: 'john doe', images: { slider: { desktop: 'link1', mo ...

Experimenting with a function invoked from a jQuery AJAX callback using Jasmine testing framework

Currently, I'm working on a function that utilizes an AJAX call to interact with a service. My main goal is to ensure the displayError function is triggered in case of a failure. The ajaxCall function is set up to accept a URL parameter. When the req ...

Utilizing AngularJs and Django for an Ajax Call

I am encountering an issue with my Ajax request as the information is not being sent until the escalando() function in the views.py file is executed. The error message displayed is: POST http://localhost:8000/escalar 403 (FORBIDDEN) I am unsure of what m ...

Create a personalized edit button for ContentTools with a unique design

I'm struggling to figure out how to customize the appearance and location of the edit button in ContentTools, a wysiwyg editor. After some research, I learned that I can use editor.start(); and editor.stop(); to trigger page editing. However, I want ...

Struggling with Getting My Animation to Function Correctly

I am trying to create a JQuery Animation that will move a div covering a text box up into the border when clicked. Despite multiple attempts, I can't seem to get the animation to work properly. Any suggestions? JavaScript function moveup(title,text ...

What is the best way to retrieve data from a fetch request within a GET function?

It seems like a simple issue, but I'm struggling to retrieve information from my "body" when utilizing the get method. I've experimented with various approaches to extract the data, but nothing seems to work. Any guidance would be greatly appreci ...

Adding an item to an array in Angular 2 using JavaScript!

In my Angular2 form, I have a field that consists of an array of objects. I've successfully created a table with a Delete Row button for each row and an Add Row button using the push() and slice() methods in JavaScript. However, there's a major ...

"What is the best way to ensure that a random array value is printed accurately within an If/Else statement in my Text Adventure

I am currently developing a text-based adventure game where the output in the console log is determined by specific input. The goal is for a message to appear if a goblin inflicts enough attack damage to reduce the player's defense to below 0, stating ...

Ways to transfer data through the javascript success function in traditional CodeIgniter

Currently, I am working with an aging CodeIgniter application. I am trying to implement an onchange function that retrieves data from the controller and displays it in an input field that is part of an array. This is a snippet of the code on the view page ...

Tips for specifically targeting the clicked table row using angularJS directives ng-show and ng-hide

Seeking assistance with implementing a toggle function in an angularJS app for showing/hiding a specific table data section. Currently, the toggling functionality is working, but it toggles every row in the table instead of just the clicked row. See this e ...

I am facing difficulties accessing an element within a controller in Angular

Struggling to access an element inside an AngularJS controller, I attempted the following: var imageInput = document.getElementById("myImage"); Unfortunately, this approach was unsuccessful as the element returned null. Curiously, when placing the statem ...

Retrieve the output of a Node.js function

I have a function that extracts data from a website and displays it in the console. However, I now want to return this data so I can perform additional actions with it. Instead of using console.log(temperature), I would like to retrieve the temperature v ...

Searching for a specific element in Vue.js using its unique identifier (ID) can be

I have a new project using Vue. It includes a div that loops through title and data. Inside the div, there is a search filter and content that renders in p tags. The p tags also go through a loop. Take a look at the code below: <div> <div v- ...

How do I switch the background-image on li hover and revert it back when I move off the li element?

Looking to update the background image of a div upon hovering over a li element? Check out this example here. So far, I've got that part working fine. But now I want the background picture to revert back to its original CSS when I move away from the l ...

What are some effective ways to address conflicts between select2 versions 3.5 and 4.0?

Although not identical, the issue outlined in this discussion thread - https://wordpress.org/support/topic/select2-conflicting-with-acf-v5 resonates with my current predicament. In the scenario of a WordPress website with two plugins, one employing select ...

What is the best way to select or deselect all asp.net checkboxes with just one checkbox event?

I am looking for a way to control the checkboxes on my webpage using a checkbox named Select All, allowing me to check or uncheck all checkboxes within individual div sections. Since my checkboxes are asp.net controls with runat=server, I am unsure how to ...

Issue with child component not reflecting changes when the state is updated

In an attempt to pass a value to a child component, I am encountering an issue where the value does not update when the parent component's value changes. Below is my code: Child Component: class Test extends Component { constructor(props) { su ...

What is the best way to retrieve error messages from a transaction with ethers.js?

Incorporating a custom error in my Solidity contract: error Documents__AlreadyExist(string hash); The modifier I utilize is as follows: modifier alreadyExist(string memory hash) { if (s_documentsHashes[hash]) { revert Documents__AlreadyExi ...

Changing a value to display with exactly 2 decimal places using jQuery

Similar Question: JavaScript: how to format a number with exactly two decimals Having successfully added values into a div with a total using some script, I attempt to convert those values into decimal numbers by dividing them by 100 to mimic currency ...

Re-sorting with _.sortBy() eliminates additional 0s from decimal values (transforming 0.10 to 0.1 and beyond)

Here is an array that needs to be sorted: var baseBetAmount = [ { val: 'OtherBaseBet', text: 'Other' }, { val: 0.10, text: '$0.10' }, { val: 0.20, text: '$0.20' }, { val: 0.50, text: ...