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!
Related
I'm using firebase firestore to save and retrieve data for my project. For reference, my data structure looks like this:
collection
document
LO3N83COzWfu:[Array]
randomisedfield2:[Array]
I'm trying to retrieve the randomised fields from the document. When I log document data, everything seems to be fine. When I try to log the field as doc.data().LO3N83COzWfu , it also works. However, I couldn't find an answer as to how I can retrieve the field, when it's requsted using a variable key such as the following:
let key = "LO3N83COzWfu";
console.log(doc.data().$[key]);
Error getting document: TypeError: Cannot read property 'LO3N83COzWfu' of undefined
How can I retrieve the field in such a case? What is the query I need to use?
I'm trying to retrieve the JSON data given below but I'm unable to.
Since I'm using Javascript Ajax success function, when I try doing alerts with the code,
$.ajax({
type:'GET',
url:myURL,
success : function(data) {
alert(data);
//{"object1":{"mainIsActive":"A","mainBuildingGL":"01493","mainIsUnderCons":"B"},"object2":[[{"statLabel":"Cafeteria","statCount":"1"},{"statLabel":"Restaurant","statCount":"2"}],[{"statLabel":"Cafeteria","statCount":"1"},{"statLabel":"Restaurant","statCount":"2"}],{"newBuildingGL":"15450"}]}
}
});
I am retrieving the below JSON data.
{"object1":{"mainIsActive":"A","mainBuildingGL":"01493","mainIsUnderCons":"B"},"object2":[[{"statLabel":"Cafeteria","statCount":"1"},{"statLabel":"Restaurant","statCount":"2"}],[{"statLabel":"Cafeteria","statCount":"1"},{"statLabel":"Restaurant","statCount":"2"}],{"newBuildingGL":"15450"}]}
But when I try trying to get the value of mainIsActive using:
alert(data.object1.mainIsActive);
I am getting the error in the console:
"Cannot read property 'mainIsActive' of undefined at Object.success (:143:30)"
Can you please help? I also attached the JSON image so you can understand the structure better.
The JSON data will be available in object structure once you have parsed it using
JSON.parse(StringYouWantToParse)
This code seems to work properly:
var x = '{"object1":{"mainIsActive":"A","mainBuildingGL":"01493","mainIsUnderCons":"B"},"object2":[[{"statLabel":"Cafeteria","statCount":"1"},{"statLabel":"Restaurant","statCount":"2"}],[{"statLabel":"Cafeteria","statCount":"1"},{"statLabel":"Restaurant","statCount":"2"}],{"newBuildingGL":"15450"}]}';
var data = JSON.parse(x);
alert(data.object1.mainIsActive);
I've been battling with this seemingly simple issue for a good two hours now.. Please educate me. I just don't undestand what I'm doing wrong.
I have a PHP script that I call from a react component with a $.get function like so:
this.serverRequest = $.get("php/get_house.php", {"id":this.props.houseId}, function(data){
this.setState({house: data, loading: false});
}.bind(this));
I then pass the data in this.state.house into another component :
<ShowHouse house={this.state.house} />
In ShowHouse component I log the data:
console.log(this.props.house);
console.log(this.props.house[0]);
The first one returns something that chrome console shows as [{...}], with the data in 0:nth position, the second one returns what you'd expect - just the data in normal JSON format like in the block below.
My JSON that I get printed on the page if I simply open the PHP-script with an id, like ..php?id=1
[{"heading":"Kuin uusi","id":"1","city":"Helsinki"}]
How do I access this data? I get an error "Cannot read property 'heading' of undefined" if I simply try to access it by
console.log(this.props.house[0].heading).
You can use array syntax
this.props.house[0]["heading"]
I am getting below error when using mssql object in script as:
var mssql =request.services.mssql;
Log entry details
ERROR
Error in script '/api/apitest.js'. TypeError: Cannot read property
'mssql' of undefined
at exports.get (D:\home\site\wwwroot\App_Data\config\scripts\api\apitest.js:3:31)
[external code]
Please suggest.
Thanks
Your problem seems to be a typo: it's request.service.mssql, not request.services.mssql as you have in your question (there's no s at the end of service). Try using the appropriate property name and you should be able to get to the mssql object.
I am trying to send POST data to my php file notify.php. For that I am using:
$.post("notify.php", { phone : phone_number });
phone_number is the input name in HTML. But the POST isn't getting sent. I used Firebug firefox plugin to check AJAX error and got:
TypeError: 'stepUp' called on an object that does not implement interface HTMLInputElement.
...i+"["+k+"]",n)}):f(i,o)}function f(i,o){o=c.isFunction(o)?o():o;e[e.length]=enco...
What is wrong?
You need to set the variable before using it, else it will give error in console and send an undefined value to the AJAX server.
var phone_number = $('#phone_number').val();
This assumes the input is defined like:
<input type="text" id="phone_number">
Try setting the variable like this first: phone_number = $('input[name=phone_number]').val()