0
I have a problem need to insert a text before returning a request in a api
:
getSW();
function getSW() {
$.getJSON("https://swapi.co/api/films", function (json) {
var data = JSON.parse(JSON.stringify(json));
var films = {
f1: data.results[2],
f2: data.results[1],
f3: data.results[3],
f4: data.results[0],
f5: data.results[5],
f6: data.results[4],
f7: data.results[6],
};
for (var i = 1; i < 8; i++) {if (window.CP.shouldStopExecution(0)) break;
$("main .row").append(
"<div class='col-12 col-sm-6 col-md-4'>" +
"<div class='item films'>"
+ "<h2 class='title'>" + films["f" + i].title.toLowerCase() + "</h2>" + "<br />" +
+ "<h1 class='title'>" + films["f" + i].director + "</h1>" +
"<div class='crawls hidden'><div>" +
"<h2>" + films["f" + i].title.toLowerCase() + "</h2>" +
"<p class=''>" + films["f" + i].opening_crawl + "</p>" +
"</div></div>" +
"</div>" +
"</div>");
I need to insert a text before films["f" + i]
....
would be
>" + "Texto Aleatório" + films["f" + i]
...– novic
I’ve tried it even carries the main ...
– Silas Dasilva
it is complicated to know its purpose, but, at the beginning of your address to correctly redeem only the
json
:https://swapi.co/api/films/?format=json
... what needs to be done?– novic
Paste a text before the api answer for example + "<H1 class='title'>" NAME OF THE DIRECTOR + films["f" + i]. director + "</H1>" +
– Silas Dasilva
I passed this in the first comment! now your code is not giving any error?
– novic
Sorry I hadn’t seen it, it worked but it appears as nanwarden...
– Silas Dasilva
I made a functional example right below!
– novic
I tried to apply the idea without success
– Silas Dasilva
You can’t do this here but, it’s because if you put single quotes on everything inside put double quotes will work yes! here for example it should be like this:
'<div class="col-12 col-sm-6 col-md-4">'
or otherwise:"<div class='col-12 col-sm-6 col-md-4'>"
– novic