How to call variable in jquery to put inside {{ Storage::url() }} - javascript

i have datatables in laravel 8 and i was encode a table to get some atribute, the code like this
Controller
i want to call r.file to get value for access the path of file,
the path file like this = "assets/file/Dr3cxy0QM2GDH1IpaWeiMZDUXfTVhl6QkazEyKYh.pdf"
Blade View
but the result like this
Browser
how to make the href value like this?
Test.pdf

You can use the jQuery .data() method to store the data in an HTML element and then access the data using the .data() method in the jQuery selector.
For example, if you have an HTML element with a class of storage-url and you want to store a variable called "url" in it, you could do the following:
<div class="storage-url" data-url="{{storage::url(url)}}"></div>
Then, in your jQuery code, you can access the data using the .data() method:
var url = $('.storage-url').data('url');

Related

How to store results of script url in Javascript variable

I am running a script in the 'head' element of a webpage that is a API call url and returns results in the form of a javascript array. The problem is that the API documentation gives me no reference to what the name of the javascript array is or how to access it, so I have no idea how to use the array in further scripts. I need a way to store the url API call results into a javascript array variable of my own that I can use.
So, is there a way to store the result of the 'head' script as a variable? Thanks, for any help.
<script lang="javascript" src="https://target_domain/db/
target_dbid?a=API_GenResultsTable&qid=5&jht=1&ticket=auth_ticket">
</script>
If you want to get the data as a javascript array: set the JSA parameter to 1. So replace jht=1 with jsa=1 in your request URL.
When you do this, it will generate a script that stores the result in a global variable called: qdb_data.
Note that the GenResultsTable call is intended to generate an HTML table and not to retrieve raw data. To get raw data I'd rather use https://help.quickbase.com/api-guide/do_query.html

How to parse url with underscoreJS

I have an url in this format:
domain.com/update/item/1
How I could retrieve the number 1 from url (for instance, parsing the url) and make me able to use it?
To give some more details about the scenario:
the page rendered associated with that url is a backbone template
called by a view
I need that value 1 to retrieve and than to use it in a html form
it will be useful if exsist a way to retrieve that value directly from the template page using the inline code (for istance, using <%
codeHere %>

passing JSTL to a Javascript function using a third javascript file

I have a JSP page and I need to use my JSTL parameter in my javascript function.
I know how to pass JSTL to javascript but I want to do it by using the third .js file because my String parameter is a big string and It's so weired to show it hardcoded in JSP page
Suppose ${data} is my data and I want to use it in javascript function which is inside my main JSP file, like this:
function x(){
....
doSomeTask(myData);
}
which I want this myData come from another javascript somewhere which does have body like this:
var myData = ${data}; //this is a different js file, lets say for example alldata.js
however this solution won't work as I tested it out !
how can I keep my data separate & call it from my jsp when I'm passing ${data} to that js variable ?
You can create object like messageMap in jsp. And create key in this object assign value ${data}.
In your jsp:
messageMap = messageMap || {}
messageMap.Key = ${data}
In your javascript file can get the element and append it content to that element:
$('.element').html(messageMap.Key)

Get json of header included link

I like to localize a website using json. Want to include the files inside the html. How can i access the json object later in javascript ?
<link rel="localization" hreflang="en" href="lang/en.json" type="application/l10n+json"/>
I don't like to use the path string directly inside javascript. Will the link element loaded automatically ? Should i use a different header tag to declare the path to the json file. How can i access header tags ?
You can use an AJAX request if you have jQuery:
$.getJSON("lang/en.json", function(data) {
alert(data);
});
Without jQuery gets complicated: Consuming JSON data without jQuery (sans getJSON)

.load() with data

I want to load data into a checkout page using .load() to load the pages in a modal window. The data that needs to be loaded is a shipping price value, that needs to be usable on the loaded page.
JS
function totalCalc() {
var shipping = ($('#shippingform input[name="shipping"]').val());
$('#cartdialog').load("/ash/shop/checkout.php",[$('#shippingform input[name="shipping"]')]);
alert(shipping);
}
CHECKOUT.PHP
$myTotal = ($subtotal + $_POST['shipping']);
I need the value which is shown through the "alert(shipping);" to be a usable value on checkout.php. You'll see I try to $_POST[] it in a php variable, but it wont work. I must be sending the data wrong...
Per the jQuery API, data sent as a query-string format string through .load() is treated as GET. Data sent as a JSON object is treated as POST. Basically, send it like this:
.load("/ash/show/checkout.php", {shipping: shipping});
As it seems you're using jQuery: http://api.jquery.com/jQuery.post/
or if you want proper control over it, use the ajax method: http://api.jquery.com/jQuery.ajax/
Alternatively, you could add the shipping cost to the URL and use $_GET

Categories

Resources