Calling mtgox API gives JS error: Unexpected token : - javascript

I get the following error when I try to get info from the mtgox API. In chrome I can see that using jsonp is working, and there's no cross domain errors:
$.ajax({
type: 'GET',
url: 'https://mtgox.com/api/1/BTCUSD/ticker?callback=?',
async: false,
contentType: 'application/json',
dataType: 'jsonp',
success: function(json) {
console.log('ok');
}
});

Related

Uncaught SyntaxError: Unexpected identifier while calling JSONP

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.

$.ajax is not working in Firefox and Safari || Error MSG : NetworkError: A network error occurred

$.ajax is not working / not posting in Firefox and Safari. I'm getting an error Message in Firefox "NetworkError: A network error occurred."
I tried keeping async:false but the data is not updating in to MySQL.
It is a cross-browser data
jQuery version is 1.12.4
$.ajax({
url: 'http://xyz.in/test/sign2.php',
dataType: 'text',
cache: false,
processData: false,
contentType: "application/json; charset=utf-8",
data: form_data,
type: 'post',
success: function (data) {
console.log(data);
}
});

IE8: Access denied

I am trying to access and API using jquery/post but its not working in IE8. Its throwing Access denied error in IE8 only.
js code:
var url = 'http://somecomp.cartodb.com:80/api/v1/map?map_key=xxxxxxxxxxxxxxxxxxxx&stat_tag=API';
var data = //some long data of length greater than 3000
$.ajax({
crossOrigin: !0,
type: "POST",
method: "POST",
dataType: "json",
contentType: "application/json",
url: url,
data: JSON.stringify(data),
success: function(a) {
console.log('success');
},
error: function(a) {
console.log('error');
}
})
If I add ?callback=? at the end of url, it still fires the error callback but with statusText: 'success' and code: 200
here is full code: http://textuploader.com/ato0w
Change dataType to jsonp will allow you to make cross-domiain requests. This will work only with GET requests.
If you're using CORS for accessing cross-origin resource, try to add the following line:
$.ajax({
crossDomain: true, // replace "crossOrigin: !0;"
});
If this not working for you, try to add the following line above $.ajax() call.
jQuery.support.cors = true;

Cannot do a post with jquery with json in body

With Chrome REST service I do this: a post to a certain url, I send a json string in the body, I set the content type as application/json and when I execute the post I get the proper answer.
I am trying to do the same post with jquery.
I first try with:
var beacon = {"beaconid.minor":2,"beaconid.UUID":"beaconnr","beaconid.major":1};
$.ajax({
type: "post",
data: JSON.stringify(beacon),
contentType: "application/json",
dataType: "jsonp",
crossDomain: true,
url: "myurl"}).done(function() {
alert("success");
}).fail(function()
{
alert("error");
});
by I seem to get no answer, I don't get the success alert nor the error alert.
I have then tried with:
var jqxhr = $.post( "myurl", {"beaconid.minor":2,"beaconid.UUID":"beaconnr","beaconid.major":1}).done(function(data, textStatus, jqXHR)
{
}).fail(function(jqXHR, textStatus, errorThrown)
{
alert(textStatus);
});
At least now I get an alert with the textStatus as an error. It is something...but not enough. I could I do a successful post?
The issue is you're setting dataType: "jsonp" for a POST request. JSONP doesn't support POST requests, only GET requests.
I suggest changing to dataType: "json" to see if the service supports CORS. If it doesn't then you'll have to do something like proxy the request through the local server, to get around CORS.
You should not be sending "post" as "type", rather as "method"
And like pointed above, the data type should be json and not jsonp.
$.ajax({
method: "post",
data: JSON.stringify(beacon),
contentType: "application/json",
dataType: "json",
url: "myurl"}).done(function(response) {
alert("success");
//if in chrome
//console.log(response);
}).fail(function(error)
{
//if using Chrome
//console.log(error);
alert(error);
});

Uncaught syntax error: Unexpected token < , ajax call

<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);
}
});

Categories