im new on AJAX and javascript and i'm trying to do and join them with an api with this structure on
{
"data": [{
"_id": "529dc2dfd0bf07a41b000048",
"name": "Junior Android"
}, {
"_id": "529dc30bd0bf07a41b00004a",
"name": "Junior iOS"
}]
}
and working my main.js
like this.
$(function() {
var $JobPositionForDd = $('#JobPositionForDd');
$.ajax({
type: 'GET',
dataType: 'jsonp',
url: 'http://localhost:8088/JobPositionForDd',
success: function(JobPositionForDd) {
console.log('success', JobPositionForDd);
}
});
});
and my index like this:
<!DOCTYPE html>
<html>
<head>
<title> Api Calls</title>
<link rel='stylesheet' href='style.css'/>
</head>
<body>
<h1> Api calls</h1>
<h2> Job Positions</h2>
<ul id="data"> </ul>
<script src="jquery.js"></script>
<script src="main.js"></script>
</body>
</html>
I've read a lot of other posts, and some answers said i have to take off the jsonp of the datatype, but if I do so I'll get an error of "No 'Access-Control-Allow-Origin' header is present on the requested resource" because i'm working on another port 8083, so, on the inspect element of chrome, gives me the error
"Uncaught SyntaxError: Unexpected token : JobPositionForDd?callback=jQuery17109280039484146982_1445751566525&_=1445751566537:2" and sends me to " "data": [ " of the json!
i don't know why it doesn't work or at least 'connect' successful, i think it's so basic what i'm doing but still is wrong, i'll be glad if someone could help me please ):