I am trying to get the data from say: http://steamcommunity.com/market/priceoverview/?appid=730¤cy=3&market_hash_name=StatTrak%E2%84%A2%20M4A1-S%20|%20Hyper%20Beast%20(Minimal%20Wear)
Which contains something like this:
{"success":true,"lowest_price":"65,84\u20ac","volume":"21","median_price":"65,19\u20ac"}
My code so far:
$.ajax({
url: "http://steamcommunity.com/market/priceoverview/?appid=730¤cy=3&market_hash_name=StatTrak%E2%84%A2%20M4A1-S%20|%20Hyper%20Beast%20(Minimal%20Wear)",
type: "GET",
dataType: 'jsonp',
success: function (data) {
console.log(data);
},
});
But I am getting the error Uncaught SyntaxError: Unexpected token :
Related
My problem with CORS, Cross origin, we search from google and found solution with JSONP, but we recieve error while calling API throught JSONP, below mycode.
$.ajax({
type: 'POST',
url: 'myapi',
data: {login:login,key:key,action:action, format:'jsonp'},
dataType: "jsonp",
jsonpCallback: "jsonp_callback",
crossDomain: true,
success : function(response){
alert(response);
},
error: function(result) {
alert('error');
}
});
function jsonp_callback(json){
alert(json);
}
Uncaught SyntaxError: Unexpected identifier
please help me and thanks in advance.
The code is in coffeescript
I am trying to read a json file using the code below (cross domain)
$.ajax
url: 'https://canttypecompanyurlhere/books.json'
dataType: 'JSONP'
jsonpCallback: 'callback'
type: 'GET'
success: (data) ->
console.log (data)
error: () ->
console.log('error')
And here's the json
{
"name": "book-1",
"author": "someone smart"
}
What am I doing wrong? I cannot get past the error "uncaught SyntaxError: Unexpected token :"
Please help
You're missing both the brackets to contain the $.ajax function parameters, as well as the braces to indicate the beginning and end of the data object, not to mention the commas at the end of each line of the object's definition. It should look like this:
$.ajax ({
url: 'https://canttypecompanyurlhere/books.json',
dataType: 'JSONP',
jsonpCallback: 'callback',
type: 'GET',
success: (data) -> {
console.log (data);
},
error: () -> {
console.log('error');
}
});
I need to fetch data from url returned data was JSON.but while trying to fetch i am getting
Uncaught SyntaxError: Unexpected token :
here is the code please check it.
can you please tell me why i am getting this error and how to solve it.
$(document).ready(function () {
var Url = "https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/ajaxGetQuoteJSON.jsp?symbol=LIBERTSHOE";
$.ajax({
contentType: 'application/json',
dataType: 'json',
url: Url + '&callback=?',
success: function (data) {
alert(data);
},
error: function (jqXHR, text, errorThrown) { }
});});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
find fiddle link https://jsfiddle.net/vbpradeep/kf9ad1t3/
it seems that you cant build the URL string inside the JSON
instead of creating it in the JSON like this:
url: Url + '&callback=?',
you can just add it to the end of the original URL string:
var Url = "https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/ajaxGetQuoteJSON.jsp?symbol=LIBERTSHOE&callback=?'";
http://codepen.io/nilestanner/pen/pEOgZj
This removes the syntax error although codepen still shows a cross origin error.
I hope this solves the issue.
$(document).ready(function() {
var Url = "https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/ajaxGetQuoteJSON.jsp?symbol=LIBERTSHOE&callback=?";
$.ajax({
contentType: 'application/json',
dataType: 'json',
url: Url
}).then(function(data){
//What should happen in success scenarios
console.log('Success');
alert(data)
},function(data){
//what should happen in failure scenarios
console.log('Failure Block');
alert(data)
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
I used laravel5.2 in my project;
javascript:
$.ajax({
type: 'get',
url: 'http://XX.XX.XX.XX/account/status?callback=?',
dataType : 'jsonp',
contentType: "application/json",
jsonp : "callback",
jsonpCallback: "jsonpcallback",
success: function(data){
console.log(data);
},
error: function(){
alert('500 error!')
}
});
route:
Route::get('/account/status', 'HomeController#accountStatus');
controller:
public function accountStatus(Request $request)
{
return Response::json(array('name' => 'Steve', 'state' => 'CA'))->setCallback($request->input('callback'));
}
but the response information has the whole html file, it turns out my route in route.php doesn't work,because whatever I changed the request url, it returns the same error and shows:
SyntaxError: expected expression, got '<'
<script>
(function(){
var searchURL = 'http://en.wiktionary.org/wiki/search';
$.ajax({
type: "GET",
url: searchURL,
dataType: "jsonp",
cache: false,
async:false,
success: function(responseData, textStatus, XMLHttpRequest){
iframe(responseData);
}
});
})();
</script>
I added this script to my html file and it is show the following errors, copy pasting the function in console is also showing the same errors.
Uncaught SyntaxError: Unexpected token <
Resource interpreted as Script but transferred with MIME type text/html
could anyone help me resolve this issue, I am using Chrome brower.
You can't request arbitrary pages via AJAX, and jsonp doesn't magically make that work. You need to use the Wiktionary API.
The URL is http://en.wiktionary.org/w/api.php.
$.ajax({
url: 'http://en.wiktionary.org/w/api.php',
dataType: 'jsonp', // will automatically add "?callback=jqueryXXX"
cache: true, // the API complains about the extra parameter
data: { // the parameters to add to the request
format: 'json',
action: 'query',
titles: 'test'
},
success: function(data){
console.log(data);
}
});