I'm following this instruction to embed the Trustpilot on my website. It will render a tag that contains the data.
I would like to check when the data is empty like this:
I found that the Trustpilot will create an object like this window.Trustpilot.Modules.WidgetManagement but still don't know how to detect that the data is empty or not.
Related
I am trying to do a simple task; retrieve JSON using Jquery and display the name to a simple HTML list, usually, the JSON file I deal with is quite straightforward with a format of
[ {a:1,b:2},{a:3,b:4}]
, but this time, the file (hosted on a different website) has a format similar to
[
["John",21,5,"description","some-link"],["Doe",3,6,"description","some-link"],]
with another 100k entries. My goal is to simply display all the names of this file in an HTML list.
Is there a way to retrieve the list and display content such as the name and description in simple HTML ul?
the actual file link is here: https://www.dropbox.com/s/104iutbz95o7wtw/test.json?dl=0 (consider it is actually hosted on a website for example: https://sample.com/test.json)
You need a regex to return a list of the data.
Have a look at this one I made for you: https://regex101.com/r/aDRp6A/1
It would help to know if the data has a strict structure or if it's variable.
EDIT:
Given your sample data I can see yours is just a list of lists. No curly brackets. That's good!
Once you have your json as a string try to split it:
myList = yourJsonObject;
And then you can access the data with:
myList[0][0]
hello you need to build your own parser or use regex, because the format that you mention is not JSON
I'm using TextAngular to save some posts to the database(with data type being text). It stores in the database like: <h1>This is a header</h1>. But when I go to retrieve from the database and display it in the HTML, it displays like <h1>This is a header</h1>.
Any idea how I can convert it either in the PHP or Javascript so it appears with the corresponding styles?
P.S.: I'm using Laravel for back-end(retrieval of data) and AngularJS for front-end(displaying data).
You don't need to convert anything.
Just use ng-bind-html.
Take a look to the documentation for more information : https://docs.angularjs.org/api/ng/directive/ngBindHtml
I need to get the name of a company into a Google spreadsheet.
The GOOGLEFINANCE function doesn't include the name of the company in its attributes, so I'm trying to create a custom function for that.
So, for IBM, for example, I can fetch the URL:
https://www.google.com/finance?q=ibm
And using Javascript, I'm trying to get the text of the name using:
document.getElementsByClassName('appbar-snippet-primary')[0].getElementsByTagName("span")[0].innerHTML
Which is returning:
undefined
If you are trying to do that inside apps scripts it wont be possible, the version of javascript in apps script does not contain the document object, therefore you won't be able to do it like that.
If you return that response to the client(where the javascript contains the document object) in order to look for the item in that way, you should have first add the information to that object.
a possible solution would be to treat the result of the urlfetch as string and then look for the information you require.
So I am working on a webpage that generates a javascript array from the date element in html.
That array itself works fine, and I am able to print it to the webpage by using a command like this:
document.getElementById("demo").innerHTML = week[0];
to access the "week" array generated within javascript and to paste it to an HTML span element on the webpage.
However, this is a webpage that sends emails using the data that the user inputs to the page, and while I am able to get all of the rest of the data from the user, I am unsure as to how to grab the data from this javascript array for the email.
The email is currently formatted using HTML with php variables. I thought about using a php array, but every solution I look up for that seems either to be for a different case or too complicated for me to dissect and repurpose.
So what I need is a solution like one of the following:
-The ability to copy this javascript array into a php array that I can then access for the email.
-The ability to access this javascript array within the HTML for the email
This is all contained within a php file on server (the HTML markup, the javascript functions and the php).
Thank you,
Michael
EDIT: I found this thread: Pass Javascript Array -> PHP
and tried their solution with this code:
Javascript:
JSON.stringify(week);
PHP:
$datesOfWeek = json_decode($_POST['week']);
But whenever I try to access the elements of the array and print them out in the email, nothing prints out for these elements.
I'm not sure what you exactly want to achieve but if you want to send a data from js (on client) along with form data to php script (on server) you should simply serialize your array and put as value of additional (hidden) form field. In php script you can somehow deserialize a value of that field (it depends on the format of you choice)
//EDIT: Here is js script example that can you use http://jsfiddle.net/zyt2kcmv/
var myArrayToSend = ["val1", "val2"]
var arrayField = document.querySelector("[name=jsArray]");
arrayField.value = JSON.stringify(myArrayToSend)
On the server side you just need to deserialize value of $_POST["jsArray"] (use library for json or simple regex). Instead of JSON.stringify you can use myArrayToSend.join(";") and then use split method in pho to "deserialize" that string.
I have a simple news update interface where I read news headlines/titles from a database and print them on page as a list. The goal is, that when I click one of the headlines it brings out an area with a form where the news article could be modified and then updated back into database.
Now in order to do that I need to somehow pass the information (an id, or the headline itself) on to the form, so I can there read the proper article and other info from the database. It seems like a very simple task, but I've come to notice it seems like an impossible task. I could of course put the whole form inside a javascript function and then pass on the headline as a parameter using this.innerHTML to the function and then read it from a variable, but then I'd have to generate all the html using javascript, or php, but I think there must be a simpler way to do this.
I've tried using a hidden input tag and others like span and div elements and then pass the headline there as the input elements value using onclick="document.getElementByID("elementsname").value=this.innerHTML;" and onclick="document.getElementsByName("elementname")[0].setAttribute("value/name", this.innerHTML);". Something like this would be so simple, but for some reason unknown to me these methods don't work. Either the info doesn't get there, or it's not further readable from the elements by javascript.
For example I can pass on the info using input element when setting it to type="text" and it shows up on the page as a text field, but it's not readable from there for some reason and it doesn't even appear on the code when checking the source code from the browser. Why is this? For that reason I can't get the info passed to my SQL query, so I could read the corresponding news article in to a textarea from database.
So, is there a way to somehow make that idea to work, or should I forget it and use other methods? How is this usually done anyway by web developers when they want to open something for editing/updating from database?
This approach is usually going to be accomplished using ajax and a separate template view for the form which is populated dynamically server side.
You will have your page of news articles. When one is clicked, it will make an ajax request to your server with an identifier for the article. The server will compose a page containing a WYSIWYG editor pre-filled with the information from the article inside of a set of input elements along with a save or cancel action.
The response from the server with this template page will come in the success callback in your page of news articles which will then popup a modal type of element containing the server side produced view.
Upon completing changes if the view is saved an update is called to the relevant news article on the page, as well as posting the changes to the server.