I've built an iPhone app that's working great so far. I've had some great help here optimising the code, but wondered if I could please obtain some help to display an error msg when the following conditions are met.
When the xml file is unavailable
When one of the xml data fields is missing (eg. brisbane is currently not listed in the xml for function 1, but should be - http://www.arpansa.gov.au/uvindex/realtime/xml/uvvalues.xml)
My current code: http://pastebin.com/VgBmdXjd
At the moment I've got the error msg working when the xml data field is empty (not missing), which should be apparent in the code. Please let me know if it isn't.
Also, both functions are setup a little differently, which might affect the way the condition is formatted. If anyone is able to explain the differences, that would be great too.
Any help is sincerely appreciated.
Kind Regards,
Glen
You need to set up the ajax error event handler in jQuery. Good Example
Related
I wrote the below line of code in my js file
var radio =
DOMPurify.sanitize($($.parseHTML(decodeURIComponent(encodeURIComponent($
(this).attr('name'))))).text());
and the checkmarx scan throws the below error at the above line
"The application embeds untrusted data in the generated output with $, at the above line of com.js. This untrusted data is embedded straight into the output without proper sanitization or encoding, enabling an attacker to inject malicious code into the output."
Can someone please tell me what I am doing wrong and what I need to do in order to fix this vulnerability issue? Thanks in advance
I have implemented DOMPurify.sanitize
I see two conflicting issues in your code.
You're encoding (this).attr('name') and then decoding it back (why?)
You don't need to use parseHtml since (this).attr('name') is already a
DOM object
You can simply write it as:
var radio = DOMPurify.sanitize(($(this).attr('name')).text());
I guess this is as much a call to attention on the fact that the documentation seems to be outright incorrect in its application, as well as just generally lacking. Normally, I would send that part of the message to them personally, but, their contact form is also giving me errors and not sending, so it's not like I have the means to anyway. In the mean time, I'm more worried about getting this code to work, so hopefully someone experienced with this SDK or an Image4io team member sees this and can provide a public answer for others stumbling into this road block.
For starters, I initialized the Image4io object as described in the github here: https://github.com/Image4IO/image4ionodeSDK/
website documentation: https://image4.io/en/documentation/api-sdk/#operation/UploadImage
The image upload example provided on the website's documentation looks like this:
let client=new Image4ioAPI.Image4ioAPI(apiKey,apiSecret);
var request = new Models.UploadImagesRequest("/folderName", true, true);
request.Add("/path/to/image/location/name-of-the-image.jpg", "name-of-the-image", "name-of-the-image.jpg");
let response=client.UploadImage(request);
3 out of the very sparse 4 lines of code they provide give errors. Where did this Models object come from? There is no corresponding class in the import and the code example obviously doesn't show where it was defined. Just what is it and where did it come from?
Well, I found a matching function "UploadImagesRequest" in the original import class, so my guess is Models was deprecated and its functionality was moved into the Image4io class object. If that was the case the solution would be to simply access that function instead... But it's not used the same. It has 4 arguments, the 4th being a "Image4io.UploadFile[]" type. This type has no use examples in the documentation or further details describing what it is exactly. I assume image byte data goes in there somehow, but how?
Finally we have request.Add... except we don't because that isn't a function :( it looks like this was used to actually get the image data (maybe of the type UploadFile?) based on the path of the image. If this function is gone now, how do get file data for use in the upload request function?
Any and all help in figuring out this SDK would be greatly appreciated. Google searches yielded no meaningful results, so hopefully we can help in that department as well. For all I know I just got the wrong version somehow. I guess I could try downgrading to a version that matches the documentation but... that's not a fix in my eyes at all.
Let me know if there's any more info I could provide to help
You can upload image like this:
var client=new Image4ioClient(API_KEY,API_SECRET);
var files=Array();
files.push(new UploadFile("./test.jpg","test.jpg"));
client.UploadImage(new UploadImagesRequest("/",true,false,files))
.then(res=>console.log(res))
If you have binary data at hand, you can write it to a temporary file and then upload them.
A few questions and I apologise if they seem unprofessional, I am a beginner programmer. But I would really appreciate any and all help you'd provide!
Currently, I have used an MQTT program to receive messages over websockets. I can view my message in the console.log but I would like to ask how can I convert it to the html output messages. is it by document.getElementById ? or is there a more better way to do that?
What is the benefit of using JSON for the messages?
What is the purpose of using variable.push(entry.anothervariable) is the push entry better and perhaps I should use an array to store the messages and then push them out?
Thank you!
Without context answering these questions are not really a good fit for Stackoverflow, but here are some answers.
Without the context of what frameworks you are using, yes finding an element with document.getElementById() and then updating it's content with .innerText or .innerHTML is probably the simiplest way forward
Sending messages encoded as JSON when working with JavaScript means that you don't need to worry about parsing any other encoding format, you can directly access fields using the native JavaScript Object Model.
This question is totally unanswerable with out any context for what you are actually working with. The .push() method is how you append an item to an existing array.
I've been really stumped on this issue for the past week and after countless hours of it not working, I am hoping someone more knowledgeable may be able to help! :)
I am creating a view pane which has a list of divs done one side holding a small bit of information such as a title and then once these have been clicked on more detailed information shows on the left. To do this have it linked up to a database which stores information ( for this it is record information).
The image attached shows an outline of what I am aiming for. There is also a screen grab of my database uploaded.
I have created the basic outline of it (albeit a rather ugly one for now! ) but I cannot get the information to show on the left hand side when it is clicked on.
The only error I have on the console is : Uncaught SyntaxError: Unexpected token <
On the connect_and_get page. I have already run the code through visual studio but didn't find any errors.
I would really appreciate any help.
Please see the code attached: https://bitbucket.org/snippets/AimeeH/je56K
Many many thanks in advance
Layout I'm aiming for
This is a syntax error
<?php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script> is not valid php. Either exit the PHP (?>) or echo the line.
For anyone who might want to reference this, I did get it working in the end although I am not completely sure as to why ( I am still very new at this!) here's what I remember doing, I really hope it helps!!
I changed all the " marks into ' (turned all the quotes into singular ones) as I read that PHP can sometimes have issues with this.
I actually uploaded the code to an online server (I used C-Panel) instead of running it on my computer with a local server running. This also meant that I made a new database for c-panel as the data would now all be accessed through this.
I added the user name in front of the table name (as this was how cpanel recognised the table name)
These were the main changes I made, and then using the console on Google chrome I worked through all the errors that popped up. As now the error messages being given were clear and useful.
I hope this helps :)
This is a beginner's question -- surely already answered but I don't know how to find it:
When a coding/system error message pops up during processing of a PHP script or possibly JavaScript, its title is usually "The page at localhost [or other URL] says:". Its content usually includes a load of non-rendered HTML code (<b>, <br>, etc), a long reference to a PHP manual, an actual error message, and a reference to where the error occurred. Because the HTML is being ignored, the whole dialog is hard to read.
How can I get such windows to appear styled properly, as surely intended by the "folks at PHP or JavaScript", or at least appear in simple text with line breaks?
Please note: It is not an error message that I am intending to pop up in response to any user action; I don't know what is causing the message. Also, I'm not seeking advice on how to make user-friendly software or on how to do continuous development-and-delivery
How can I get such windows to appear styled properly, as intended?
I don't know which window you are talking about, however from the rest of your description it sounds to me that you want to turn HTML error off so to get the plain text version of the error messages.
PHP has a setting for that Docs:
html_errors boolean
Turn off HTML tags in error messages. The new format for HTML errors produces clickable messages that direct the user to a page describing the error or function in causing the error. These references are affected by docref_root and docref_ext.
So all you need to do is to turn if off, either in your php.ini:
html_errors = 0
Or within your code:
<?php
ini_set('html_errors', 0);
You might also be interested in:
How to get useful error messages in PHP?
Never have your errors show up in a production website!!
If you're talking about dealing with errors while you're developing, then check out the Whoops library. It'll give you everything you want, plus much more.
Here's a quote from their homepage:
whoops is a nice little library that helps you develop and maintain your projects better, by helping you deal with errors and exceptions in a less painful way.
Check out their demo here. You can click on the left side to go through the stack. Really cool.