I'm creating a single HTML page that displays a summary. I've got four other queries and I've had no issues. But, I would like to display the recovery status when there's an issue and I'm getting an error. Once I get this query working, I'll pull out what I need and display it in a table. But, for now my basic code is below:
function showRecovery(){
client.cat.recovery().then(function (resp) {
console.log("Recovery status is:\n", resp);
});
}
It returns error "Uncaught (in promise)" and this message:
Serialization {message: "Unable to parse/serialize body",...
Related
So I'm desperately trying to pull a value from a 3rd party website API. The information is formatted in the following way:
Website's API response
I'd like to pull out a value for "price". So far I've tried many different codes but all have failed. I've also spent a lot of time searching for a solution but without succes. At the moment my code for obtaining the value looks like this, but it's obviously not complete and incorrect as I'm new to NodeJs:
var Request = require("request");
Request.get("url", (error, response, body) => {
if(error) {
return console.dir(error);
}
console.dir(JSON.parse(body));
});
And yes the url is actually inserted in my code + I know that this should only display the full JSON structure, but it fails to do even that :/
Any kind of advice would be welcome :)
EDIT: So I've fixed that issue with not getting data :) However I still need to filter my data in order to pull out the "price" value. As of now my data displays this: "data: { items_on_sale: [ [Object] ], items_not_on_sale: [] } }"
status: 'fail' : The api is not replying with the data.Does the url require any query params/body to be passed with the url?
Try hitting the api using postman/SoapUI and check the response there.
also try printing the response in the log,what values do you get?
console.log('statusCode:', response && response.statusCode);
There was a problem with 2FA code. It wasn't generating properly. It is now fixed.
When attempting to run the following code:
try{
document.getElementsByClassName("aklsdjfaskldf")[0].outerHTML;
}catch(err){
alert("Function failed with error dump <"+err.message+">");
}
the error message displayed is truncated:
Function failed with error dump <document.getElementsByClassName(...)[0] is undefined>
Is there a way for the error message to be displayed in full, i.e. display the following message in Firefox? Chrome does not display the output, and therefore is not an issue for my current usage.
Function failed with error dump <document.getElementsByClassName("aklsdjfaskldf")[0] is undefined>
Every browser handles the error call stack differently, if you are on chrome you wont even see that string. It would simply say cannot invoke that outerHTML function on undefined. So better you check the value before invoking a function on that and then show the appropriate alert. Or you print the error.stack if you want to get a hint about the location of the code throwing this error.
I have a Django web app which has various instances of ck-editor instances on a web page.By using on blur event I am saving whole of data of the instance in the database -
{% for editor in editors %}
CKEDITOR.appendTo("{{editor.ck_id}}" ,
{
on: {
blur: function(event){
var data = event.editor.getData();
console.log("data of {{editor.ck_id}} is " + data);
var request = $.ajax({
url: "/editor/save/",
type: "GET",
data: {
content : data,
content_id : "{{editor.ck_id}}"
},
dataType: "html"
});
}
}
}
// "{{editor.data}}"
);
CKEDITOR.instances['{{editor.ck_id}}'].insertHtml("{{editor.data}}");
Here ck_id and data are the two database fields of ckeditors.Now suppose I write this on one instance of ckeditor -
Tony Stark
When I lose focus on that instance then on blur event is fired and I use 'getData()' to get the html data of that instance.
<p>Tony Stark</p>
is saved into the database.On the python interpreter now when I fetch editor's data it shows -
<p>Tony Stark</p>
which is obvious.
Now When I re start the server and set the data of every ck-editor instance again then this exception is raised -
Uncaught SyntaxError: Unexpected token ILLEGAL
I know why this is happening - due to this -
CKEDITOR.instances['ck_1'].insertHtml("<p>Tony Stark</p>
");
The data which I sent by fetching from database was -
<p>Tony Stark</p>
and it somehow got converted to above mentioned text with illegal tokens.I have tried to use setData() but with no result. Do I need to encode/decode this HTML or something?
Now my question is how to again reset data to a ck-editor instance which I fetched from it and stored in database. I have posted this question on several forums but many people have got no clue of what I am asking?
Is there anyone here who has tried to do same thing and have succeeded in it?
Thanks
PS: Adrian Ghiuta solution seems to be working but there is just problem. When the editor is loaded first time then in google chrome's debugger inserted line is seen as -
"<p>Tony Stark</p>"
which is rendered due to line "{{editor.data|safe}}".But when I change my editor's content to just
Tony
then in database
<p>Tony</p>
is being saved but when I restart the server it does not render and throws this error
Unexpected ILLEGAL TOKEN
due to this -
"<p>Tony</p>
"
Here ending double quotes are in the next line.But during initial data loading it was on the same line.Might this be causing be any problem?
Because my chrome console shows error at that position.
I will add some images to show the condition.
Initial loading -
Initial console -
Editor after editing -
Error being shown after restarting server and reloading editors -
Console -
You can see how error is thrown at line where double quotes are at the next line.Do I to escape html or something?
Sorry for my naivety but I do not have much command over HTML.
Please have a look. I am getting an error of "Uncaught type error: can not read the property 'title'".
here is how code looks like :
db.transaction(function(transaction) {
transaction.executeSql('INSERT INTO post_details(post_title, post_date,post_comment,post_content,post_categories,post_image) VALUES ("'+data.posts[i].title+'","'+data.posts[i].date+'","'+data.posts[i].comment_count+'","'+data.posts[i].content+'","'+data.posts[i].categories+'","'+data.posts[i].thumbnail_images.full.url+'")',[], nullHandler,errorHandler);
});
This "data" is a variable holding JSON data which i am calling through AJAX. Which is returning properly if am normally alert it.
Thank you!
I got this javascript code in a JSP:
$('#myForm').submit(function(event) {
event.preventDefault();
var act = $('#myForm').attr('action') + '&act=' + $('#submitBtn').val();
var dataStr = $("#myForm").serialize();
$.post(act, dataStr, function(data, status) {
$('body').html(data);
});
return false;
});
The facts:
I'm using jquery v1.3.x (and I can't replace with newer version because of company policy).
The jsp is in a pop-up window.
There is a submit button with id=submitBtn
When the submit button is clicked, it will execute above code and send the data into struts action.
The action url:
someAction.do?someParam=blabla&someNo=213354345&mode=POP&act=Update Your Data
(note: I had replaced some sensitive data, but the argument pattern is same)
The problem is at this line:
$('body').html(data);
It produces Error: NS_ERROR_FAILURE: Failure in error console. I heard it's related with cross domain request, but my application is at localhost, how could it happened?
In IE 8, it successfully replaced the current page content with the data value (which is html string). But in firefox (v22), it gave blank page, I checked with right click -> View Source, it's really empty. Then I checked with firebug, the response data indeed contains the result html page string. If I debug with alert(data); before the $('body').html() call, it also show the html string.
So the $.post() function successfully returns the response data but it seems the $('body').html() function failed to render the data.
So what is actually happened? I'm really have no clue.
What is the solution for this?
UPDATE:
I checked the error console, I got this error after submitted the page:
Error: NS_ERROR_FAILURE: Failure
Source File: http://localhost:8080/myapp/script/jquery.js
Line: 19
UPDATE 2:
I debug the java code, I found out that the input html tag in the JSP that has indexed array name like this:
myItem[0].name
myItem[1].name
...
were not successfully submitted to the ActionForm class. I investigated the source of problem might come from a 3rd party javascript library.
try something like this
$.post(act, dataStr, function(data) {
document.body.innerHTML = data;
});