Can we have a shared file, define a variable, and use it in all .cshtml pages? (Razor)
I have this call:
ajaxCall({
type: "GET",
url: '/api/getOrder?version=3.0&body=true',
contentType: 'application/json',
success: function (response) {
…..
}
});
I wanted to define the version as a variable in a single file and use it on all pages, I know I can define it on each page, but is it possible on a single page and call on all other pages?
Related
I am using an AJAX request and Handlebars to communicate the data transfer as shown below.
main.hbs
<script>
..
$.ajax({
type: "POST",
data: JSON.stringify({
propId: "{{staysAt}}",
propImg: "/{{propImg}}",
_csrf: "{{csrfToken}}"
}),
contentType: 'application/json',
dataType: 'json',
url: "/user/sendRequest",
success: function(result){
},
error: function(err){
//console.log(err);
}
})
..
</script>
In propImg data is being stored as
/uploads 8-11-27T10-54-19.118Zparis-graph-colored.png
Instead of
/uploads\2018-11-27T10-54-19.118Zparis-graph-colored.png
When i use main.hbs to display the Handlebar object outside the AJAX request it works perfectly
<h2>/{{propImg}}</h2>
and gives the complete image path, however inside the AJAX call I do not understand what is going wrong.
I tried using {{{propImg}}} for no escape as well however the same issue is coming.
I'm a beginner in google app script. The two function in separate file id declared and it works on google debug well.
Therefore, I deploy to web application but when I connect the API and it only returns my first function (onGet).
Is possible like node or php that could use a different name to call another API? i.e. API/A_WEB_SERVICE . API/B_WEB_SERVICE.
Or I need to add a new project to handle my situation?
my.js
$.ajax({
type: "get",
url: "https://script.google.com/macros/s/my_key/exec",
data: data,
dataType: "JSON",
success: function (response) {
console.log(response);
alert('cool works.');
}
});
gs
doGet(){} // in my first file.
doDebug(){} // in my second file.
I am having real difficulty knowing what to do. I have been reading some sources that are inferring that you cannot make ajax calls when launching an html file from the local file system (file:// in the url).
I have a html file on my desktop (ie in the browser url file://) containing the following ajax call:
$.ajax({
type: "POST", // This for array
url: "http://www.mywebsite.com/exclude.php",
async: true,
cache: false,
crossDomain: true, // This needs to be true for other people
success: function (data) {
var json = jQuery.parseJSON(data);
// Use json in interesting ways
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// Silent error
}
});
My php file on my server is basic:
<?php
header("Access-Control-Allow-Origin: *"); // To allow cross domain
$KeyCodeStatics_BlackList = ["181K2", "4V419"];
echo json_encode($KeyCodeStatics_BlackList);
?>
Some are suggesting ajax calls are not allowed from an html file launched in the local file system (file:// in url).
The errors I am getting:
Origin file: not found in Access-Control-Allow-Origin header.
and
XMLHttpRequest: Network Error 0x80700013, Could not complete the operation due to error 80700013.
How can I overcome this? I need to make an async call to /www.mywebsite.com/exclude.php from the html file from my local file system.
Note: It is not just me that has to do it, it is every end-user that uses this html file. So this means I cannot ask them to change security settings on their browser.
I need to load some data (A WordPress Menu) from an external REST API into my Shopify template. I'm assuming I need to use an App proxy to do this. I've looked through the documentation but I'm a little confused as to how to go about this.
Can anyone point me in the right direction?
I often use jquery with an ajax call to an api end point that either
sends me back formatted html
send me back json data that I parse and form the html via javascript.
jQuery(window).load(function(){
data = {};
jQuery.ajax({
type: 'GET',
url: 'https://yourapp.herokuapp.com/yourendpoint.json',
data: data,
dataType: 'json',
success: function(data) {
console.log(data);
$.each( data, function(i, item) {
console.log(item);
// do something with your data here
});
}
});
});
I am trying to call an asmx web service in plain html page. But not getting output. I'm not getting the exact problem. Here is my ajax code that I wrote to call that asmx web service.
function Getdet(Name)
{
alert('hellotest');
$.ajax({
type: "POST",
url: "http://192.168.1.20/myservice/service.asmx?HelloWorld", // add web service Name and web service Method Name
data: "{''}", //web Service method Parameter Name and ,user Input value which in Name Variable.
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response)
{
alert('abcd1');
$("#spnGetdet").html(response.d); //getting the Response from JSON
},
failure: function (msg)
{
alert(msg);
}
});
}
Should I have to add anything in the code..?? Please let me know where I am going wrong in this above code.
ASMX pages are plain old Web Services and the output is (almost) always in XML format, so don't except JSON out of the box.
Plus, they don't work well on different domain call by default, you will need to ensure that the cross domain is correctly handled.
After all this is done, you will then use the call as:
success: function(response) {
// http://stackoverflow.com/a/1773571/28004
var xml = parseXml(response),
json = xml2json(xml);
$("#spnGetdet").html(json.d);
}