Shopify - Loading data from an External REST API in a Liquid template - json

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
});
}
});
});

Related

Pass AJAX param and access it from expressjs side of application

I feel like I am missing something here.
To start, you have an AJAX call you can do in tag to post data to the backend, which looks something like,
function changeDom(){
console.log('connecting');
$.ajax({
url: '/loadOrders',
method:'POST'
}).done(function(data){
if(data.success){
$('#recentOrders').append(data.message);
changeDom2();
return;
}
}).fail(function(){
console.log('failed');
return;
});
};
And on the backend you receive it with code that looks something like,
app.post('/loadOrders', function(req,response)
{ // code here });
I have seen that it is possible to pass a parameter along an AJAX call, which looks like,
$.ajax({
url: '/loadOrders',
method:'POST',
data: {field1: 'this is data being passed'}
}).done(function(data){}});
But how would I receive that data on the backend? How would that change in syntax look and how would I call the parameter?
You can get it by doing
req.body.field1

google app script: same api with different file

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.

Which is faster than react js and regular html ajax for json parse?

I studied react js.
I would like to know the benefits of React js for json parse. !!!!
I know that react is very fast because virtual dom and data flow.
What I was wondering is JSON parse.
In general html, we use ajax to do a json parse.
for example...... like this:
$.ajax({
dataType: "json",
url: url,
data: data,
success: success
});
In the case of React, ....
There are many ways, but if you use axios-redux-node-react js.
like this ....
// Performing a GET request
axios.get('https://api.github.com/users/' + username)
.then(function(response){
console.log(response.data); // ex.: { user: 'Your User'}
console.log(response.status); // ex.: 200
});
so, finally
1. Which is faster than react js and regular html ajax for json parse from url (dynamic asynch..... )???
2. What is the fastest way to do json parse with react js?
I need example ...... please ... please!!!

How to call .asmx web service using plain html page

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);
}

How to write a simple webservice which returns JSON object on ajax call in jQuery Mobile

I'm working on jQuery Mobile application which should get the data from the webservice based on the selected item in the form in jQuery mobile.
$("#catalogue").live('click',function(){
$.ajax({
type: "GET",
url: "LifeService\log",
data: "json="+$("prodcat");,
dataType: "json",
success: function (msg) {
alert(msg);
}
});
});
This function doesn't return anything. When I simply run the webservice in browser with the value, I get the success message. Can anyone tell me how to call the webservice from jQuery Mobile?
Where are experiencing a problem? Posting the code you've got so far would help. jQuery offers the getJSON() function you need, and you can then parse the resulting string back into a usable JSON object with parseJSON().