jQuery now showing the phrased variable value - javascript

Stuck on the first stage of a big project. I am trying to display the JSON value that I get from URL shown below. It shows the data when I past the URL on the a browser. But when I put the URL in variable and try to show in html it doesn't show the phrased value.(I will delete the app/key one I get the solution.) Thanks in advance.
http://jsfiddle.net/rexonms/6Adbu/
http://api.flickr.com/services/rest/?format=json&method=flickr.photosets.getPhotos&photoset_id=72157629130565949&per_page=10&page=1&api_key=ccc93a20a1bb9060fa09041fa8e19fb5&jsoncallback=?

Have you tried using the $.getJSON() or the $.ajax() method? This seems to return the data just fine:
$.getJSON(apiCall, function(data) {
console.log(data);
});
Here's a working fiddle.
Additional Information
It seems like you may benefit from a simple tutorial that explains AJAX in relation to jQuery's $.getJSON() and $.ajax() methods.

$("<span>").html(apiCall)
apiCall is a string (containing the URL). All you're doing here is setting a span to have the URL as its content. You need to actually use AJAX to load said URL.
$.ajax({
url: 'http://api.flickr.com/services/rest/',
dataType: 'jsonp',
type: 'GET',
data: {
format: 'json',
method: 'flickr.photosets.getPhotos',
photoset_id: '72157629130565949',
per_page: 10,
page: 1,
api_key: 'ccc93a20a1bb9060fa09041fa8e19fb5'
},
jsonp: 'jsoncallback',
success: function(data){
console.log(data);
}
});
Inside success, data is the JSON object returned by the API.

Related

Cant pull data from JSON array

Currently I am trying to pull data from my steam inventory using the following link: http://steamcommunity.com/id/STEAMID/inventory/json/730/2. Using the link I can see the results in browser however when I actually try to pull the json with $.getJSON I simply cant figure out how to get it to work. Here is a simplified version of the code.
<script>
$( document ).ready(function() {
var items = {"rgIventory" : "4932985723947"};
var url = "http://steamcommunity.com/id/STEAMIDHERE/inventory/json/730/2";
$.getJSON(url, function(data) {
document.getElementById("placeholder").innerHTML=data.rgInventory;
});
// document.getElementById("placeholder").innerHTML=items.rgIventory;
});
</script>
This is just a simple project im trying to do, I want to eventually list everything in a nice table with the items according image. I just cant figure out how to pull in the JSON. Sorry for the stupid question I've just been working on this for a day now and can't wrap my head around it.
Thank you all in advance.
EDIT: Can someone post an example of what I need to do? Very confused.
Try using json. Example given below
$.ajax({
type: 'GET',
url: '//steamcommunity.com/id/STEAMIDHERE/inventory/json/730/2',
async: false,
jsonp: "callback",
jsonpCallback: 'someCallBackFunction',
contentType: "application/json",
dataType: 'jsonp',
success: function (data) {
console.log(data);
//do your stuff
},
error: function (e) {
console.log(e);
}
});

Trouble with posting jQuery to JSON

I am trying to write a script that allows posting to a JSON file. For some reason the process is succeeding, but the JSON file isn't being written to.
Here is my jQuery code:
$(function() {
var data = {
name: 'cool',
drink: 'cool2',
};
$.ajax({
type: "POST",
url: '/api/orders',
dataType: 'json',
async: false,
data: JSON.stringify(data),
success: function() {
alert("Thanks!");
}
})
});
Here is my JSON code (/api/orders)
[
{"id":1,"name":"Ben","drink":"Americano w/ Creme"},
{"id":2,"name":"Ben2","drink":"Americano w/ Creme2"},
{"id":3,"name":"Ben3","drink":"Americano w/ Creme3"}
]
I can't figure out why Chrome is saying it is succeeding, but the code isn't posting to the JSON file.
The problem isn't with your JavaScript. The JSON.stringify just concerts the data to a JSON string and passes it to the url. Your problem will be in the Url that it is posted to /Ali/orders. That looks like a directory to me instead of an API to handle the string. I could be wrong in that as certain technologies hide that stuff. Still you need to look at where the data is going to.

How can I pull content from blogger onto my webpage?

I want to dynamically pull the posts from blogger to my HTML/CSS/PHP webpage. What would be the best way to go about doing that?
For that, should I use JavaScript, PHP, AJAX or something else?
You could use jQuery .ajax() request using Blogger API.
https://developers.google.com/blogger/docs/3.0/using#RetrievingABlog
For example: (something like this, not tested)
$.ajax({
type: "GET",
dataType: "jsonp",
url: "https://www.googleapis.com/blogger/v3/blogs/2399953?key=YOUR-API-KEY",
success: function(data) {
console.log(data);
}
});
For posts it looks like you will need to use this URL and whatever your API key is.
https://www.googleapis.com/blogger/v3/blogs/2399953/posts?key=YOUR-API-KEY

Serialize the data from 3rd party API in javascript/jQuery

I want to do a serialize the data that I got from 3rd Party API. The following Picture is what I got from the API
As you can see in the photo, I have received 2 sets of the Information which indicated by the number in the []. And when I do the POST request using jQuery, the multiple Parameters Posts to my Java method. What I would like to do is to encapsulate each set ot the Information into a Group and after that serialize them in one parameter and sent it back as one object that hold all the things inside.
How can I do it by Javascrip or jQuery???
anyway, this is my code
function getMediaInfo(InkBlob){
console.log(InkBlob);
jQuery.ajax({
type: 'POST',
url: '/webapp/filepicker/importAssets',
dataType: 'json',
data: {"inkBlob": InkBlob}
}); }
All I want to do is to set only one parameter call inkBlob that contains the Information as Show in the photo above.
How about -
For Serializing js object
var str = JSON.stringify(InkBlob);
jQuery.ajax({
type: 'POST',
url: '/webapp/filepicker/importAssets',
dataType: 'json',
data: {"inkBlob": str}
});
Note
JSON.stringify is not available for older browser, use JSON2.js for older browsers.

javascript object to php

i'm trying to send an js object to a php function using jquery.ajax.
This is what i have so far:
js side:
$.ajax({
type: "GET",
dataType: "json",
url: url,
data: {persoon : persoon2},
async: false,
success: function(){
alert(data);
return true;
}
});
php side:
$decode = json_decode($_GET["persoon"]);
$verzekering->setVoornaam($decode->persoon_voornaam);
in js this works: persoon2.persoon_voornaam
but i can't get to the value in php, what am i doing wrong?
few fixes
data: "persoon=persoon2", // check input format
success: function(data) { // missing data argument
EDIT your ajax code is working (check URL or php code)
http://jsfiddle.net/ish1301/KZndE/
Found the problem(s)
I was using this inside Drupal and the Jquery version was still 1.2.6. Upgrading it resolved a lot of the problems
The string i tried to catch with the $_GET["persoon"] was mall formated becaus i just send along a js object. Changing
data: {persoon : persoon2},
to
data: {persoon:JSON.stringify(persoon2)},
fixed the problem

Categories

Resources