json file images won't load in ionic page - json

I am trying to load some images from a file on a server to display on a list. I get 404 not found error
after asking in forums, I get that the request URL is wrong, it looks inside the localhost not inside the json file.
https://filehost.net/db54d37849f75ddd
in the code I have a service which returns a response. I use that response in a controller and to the view. I get other information but no images
if anybody has a solution that would be really great.

please attach also some code, in this way it is easier to help you. About the problem, do have correct form of $http GET request? I mean does your get request points to correct address on server? something like this
`
// Simple GET request example:
$http({
method: 'GET',
url: '/someUrl'
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
`
you can check more here Angular $http

Related

Problems with JSON getting data from tmi.twitch.tv api

Problem is when i try to use this code to get the log from tmi.twitch.tv api using url: http://tmi.twitch.tv/hosts?include_logins=1&target=70219146 i get Systax Error Unexpected Token. The code is:
$(document).ready(function() {
$.getJSON("http://tmi.twitch.tv/hosts?include_logins=1&target=70219146&callback=?", function (data) {
console.log(data.hosts)
});
})
I can get the data using php and json array like this:
$json_array = json_decode(file_get_contents('http://tmi.twitch.tv/hosts?include_logins=1&target=70219146'), true);
echo $json_array['hosts']['0']['host_login']."</br>";
But isnt there a way to use do this in html? thanks
You are trying to request regular JSON as JSONp (&callback=? activates jQuery's JSONp request method) which actually embeds the response into a <script> to execute it. However, the twitch API still returns JSON which is not valid JavaScript. Unless there is a way to make tmi.twitch.tv return valid JSONp, there is no way to do this directly from JavaScript unless you use a proxy like http://crossorigin.me/.

pass ajax response (json)data in php

So, I am stuck here and feel like banging my head.
My problem is I query a database by ajax and returned its response in json form. Now I have this response in the form of javascript variable but I want to pass it to a php variable for further use.
How can I do that ??
function getJson(url){
return JSON.parse($.ajax({
type:'GET',
url: url,
dataType:'json',
global:false,
async:false,
success: function(data){
return data;
}
}).responseText);
}
Here how do I pass data to php ??
FIrstly I gave you -1 for not learning the basics!
- You can send client values to server (php) as querystring
example: /server_link?json=JSON_VAL
(not recommended for whole json string)
- Send it as post body (look for jquery ajax post) and parse it with php json library.
- if you have just single level json ({name:'John', sname:'Smith)} you can send it to php server(as mentioned before ajax post) and read as request variable in php ($_POST, $_...).
As I never programmed in php you'll have to do it you're self.
A again: LEARN THE BASICS (client side, server side, post, get,...).

HTTP "DELETE" request hangs on Elastic Beanstalk

I deployed to AWS for first time, and experienced a very strange behavior. I use AngularJS and there is a function that performs $http service call with DELETE method specified.
var fn = function () {
$http({ method: "DELETE", url: "/active/route/"})
...
and when I perform it, request hangs for a while and get refused.
I've changed fn to
function () {
$http({ method: "POST", url: "/active/route/delete"})
...
And it worked just fine.
I want to know if beanstalk has specific policy about some HTTP methods or what was causing this behavior?
I know this has been fairly inactive for a while but I figured out what was happening in my case and thought I would post it here for anyone else who needs it. Basically http DELETE methods do not play nice if you are sending a request that contains a request body. Pure RESTful services should be employing the URI to pass object ids back and form, rather than form data or in the request body. When the data is passed via request body some web servers will read that as a POST method, which can wreak havoc on your API.
In my case I was passing the object id both in the URI and, as a side effect of my architecture, in the request body. This works perfectly ok in all cases except DELETE. To fix the issue I simply removed the unnecessary request body and viola!
Hope this helps someone.
See this post for more detail:
http://www.spenceruresk.com/2011/11/http-delete-requests-that-include-a-body/

Not able to fetch the json response through angularjs

Need to fetch the build values from apache.org. So i am using their api
https://builds.apache.org/api/json
I tried angularjs $http.jsonp but not able to fetch the data.
In chrome console under network json api is getting loaded but the data is not getting returned instead it is throwing the response as error.
app.controller("jsoncontroller",function($scope,$http){
var url='https://builds.apache.org/api/json';
$http.jsonp(url).success(function(data){
console.log('success');
})
.error(function () {
console.log('error')
});
});
Getting the error as
Uncaught SyntaxError: Unexpected token :
error
As per the jsonp angular docs, you must append JSON_CALLBACK to the URL: https://builds.apache.org/api/json?jsonp=JSON_CALLBACK
However, that URL doesn't work because even when the callback parameter is specified, the server still sends back a content-type of application/json, instead of the expected application/javascript. This causes it to be parsed (evidently) by the json parser instead of the javascript callback needed for JSONP to work. I'm not versed enough in JSONP or Angular to know who is it fault here.
I've made a fiddle with this working with another URL.
[Update]: The apache build server appears to use Jenkins, which has disable JSONP from the remote API. You can verify this yourself by trying to hit their jsonp endpoint, which returns a 403. You'll have to use another endpoint, no way I can see around this.

play framework routes trouble (400 bad request)

I'm having trouble making a POST to the play framework - this may not even be Play related as much as HTTP related.
$.ajax({
type:'POST',
url:'http://localhost:9000/start',
data: {
myJson:JSON.stringify(arg)
}
}).done(function(data) {
console.log(data);
});
where arg is an array of strings, ie:
['a', 'b', 'c']
The route I'm trying to use to capture this is:
POST /start controllers.Application.startIt(myJson)
What am I doing wrong? As of right now (if the route is capturing correctly), that function will never return a 400. There is no output to the Play console, only javascript:
POST http://localhost:9000/start 400 (Bad Request)
The documentation explains when a BadRequest error code is returned by the framework. The problem comes from your router file. You define a route /start which will trigger a method call startIt, but the method has an argument and the framework does not know which value it should pass.
To handle correctly JSON requests, have a look to the dedicated part of the documentation.