I am new in jQuery. But what I found is it is very easy to use with any Javascript functions.
What I am trying is to achieve -
this or this
address's JSON data in my page with Javascript with help of jQUery.
Page Content is simple JSON data-
{
"firstName": "John",
"lastName": "Doe",
"age": 25
}
What I have done in jQuery is-
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function ()
{
$.ajax(
{
type: 'GET',
url: 'http://www.w3schools.com/jquery/demo_ajax_json.js',
dataType: 'jsonp',
success: function (data)
{
console.log(data);
$.each(data, function(index, element)
{
console.log(index + element);
});
},
error:function(e)
{
console.log(e.message);
}
});
});
</script>
And What I am getting in every time is -
In Chrome-
Uncaught SyntaxError: Unexpected token :
In Firefox-
SyntaxError: missing ; before statement "firstName": "John",
I have tried many times and searced everywhere for its solutions.
But I can't get a proper solution.
Can anyone please help me?
Thanks in advance for helping.