I have be writing code for Json requests, but haven't seen this before..
How do I go about it?

I want to return all the countries with their name and Phonecode

Here is the Json am getting request from:


    "af": {
        "name": "Afghanistan",
        "phoneCode": "93"
    "al": {
        "name": "Albania",
        "phoneCode": "355"
    "dz": {
        "name": "Algeria",
        "phoneCode": "213"
    "ad": {
        "name": "Andorra",
        "phoneCode": "376"

I want it to return this:

<div id="results"></div>


        $(document).ready(function() {

                //start ajax request
                    url: "data.json",
                    success: function(data) {
                        var json = $.parseJSON(data);
                        $('#results').html('Country: ' + json.[0].name);



Recommended Answers

All 3 Replies

Member Avatar
function getData() {
            url: "countries.json",
            success: function (data) {
                var json = $.parseJSON(data);
                var output = '<ul>';
                $.each(json, function(i,v)
                    output += '<li>ObjectName: ' + i + ' Country Name: ' + v.name + ' Number: ' + v.phoneCode + '</li>';
                output += '</ul>';

Thanks for the reply @diafol, missed that '$.each()' function.
Please, If I do want to use it a typeahead like:

Typeahead one: Input country
Typeahead two: Input states


<input type="text" id="list-countries"/>

<input type="text" id="list-states"/>


If 'typeahead one' = Canada

                                'typeahead two' should list states in Canada: like texas...

Expecting your opinion soon.

Member Avatar

This is a different question. Start a new thread. Mark this one solved if the original question was answered. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.