Languages

Menu
Sites
Language
I want to retrieve data from website to mobile application.I have used JSONP but it not work

Hi,

   I have implemented but it not work.I have implemented in two ways.                            

$(document).ready(function () {
    $.getJSON('http://apibeta.yourstory.com/v1/sites', function(jd) {
    alert(jd.social_media.facebook);    
    });


    });


------------------------------------------------------------------------------------------

$.ajax({
    url: "http://otter.topsy.com/urlinfo.js?url=http://www.nytimes.com",
    dataType: 'jsonp',
    success: function(results){
        var title = results.response.oneforty;
        var numTweets = results.response.trackback_total;
        $('#results').append(title + ' has ' + numTweets + ' tweets.');
    }
});

 

 

 

Please help me

Mohit Kumar

 

 

View Selected Answer

Responses

10 Replies
AVSukhov

Hello,

Do you add external resource to access tag in config.xml?

mohit kumar

Hi AVSukhov,

    Here is my config.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" id="http://yourdomain/YourStory" version="1.0.0" viewmodes="maximized">
   
    <access origin="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js" subdomains="true"></access>
   
   <access origin="http://api.fixer.io/latest" subdomains="true"></access>
    <access origin="*" subdomains="true"></access>
   
    <tizen:application id="I7KACWdFdG.YourStory" package="I7KACWdFdG" required_version="2.3"/>
    <content src="home.html"/>
    <feature name="http://tizen.org/feature/screen.size.all"/>
    <icon src="icon.png"/>
    <name>YourStory</name>
     <tizen:privilege name="http://tizen.org/privilege/internet"/>
    <tizen:profile name="mobile"/>
</widget>

 

colin Rao

Hi,

Seems the code is ok. What's the error message? And did you add the internet privilege and the access policy into config.xml file?

Mark as answer
colin Rao

as your code:

$.getJSON('http://apibeta.yourstory.com/v1/sites', function(jd) {
    alert(jd.social_media.facebook);    
    });

open the url 'http://apibeta.yourstory.com/v1/sites' in browser, seems the returned json result is an array, try it once more as below,

$.getJSON('http://apibeta.yourstory.com/v1/sites', function(jd) {
    alert(jd[0].social_media.facebook);    
});

 

mohit kumar

Hi colin Rao,

You are like GOD

Thank you so much.
 

 

 

 

Thanks and regards

Mohit Kumar

Palitsyna

Hello,

as said above, add acess tag and internet privilege into config.xml file.

<tizen:privilege name="http://tizen.org/privilege/internet"/>

<access origin="http://your-web-site.com" subdomains="true"/>

 

Vikram

Hi,

You can also using this code to get the all data

$.getJSON('http://apibeta.yourstory.com/v1/sites', function(jd) {
                $.each(jd, function(i){
            		alert(jd[i].social_media.facebook);
                	});            
            });

 

Palitsyna

Hello,

just FYI, here is a jQuery's JSONP tutorial with examples: http://www.sitepoint.com/jsonp-examples/

Seoghyun Kang

Hello,

 

You can use the XMLHttpRequest. It works well on Tizen.

 

Please refer the following codes.

var xmlhttp, xmlDoc, dataItem;
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", XML_ADDRESS, false);
xmlhttp.onreadystatechange = function() {
    var weatherInfo, tempInfo;
    if (xmlhttp.readyState === 4) {
        if (xmlhttp.status === 200) {
            xmlDoc = xmlhttp.responseXML;
            dataItem = xmlDoc.getElementsByTagName('item');
            if (dataItem.length > 0) {
               // TODO
            } 
            xmlhttp = null;
        }
    }
};
xmlhttp.send();

 

colin Rao

but, I think it's not ok for the JSONP, a crass domain access solution.