Im using this:
$.ajax({
url: 'http://api.geonames.org/searchJSON?username=presis',
dataType: "jsonp",
data: {
name: city,
countryName: country,
maxRows: 1
},
jsonp: "jsonp",
success: function(data) {
$.map(data.geonames, function(item) {
return {
value: item,
};
});
}
});
I just can't get it to work. What could the problem be?
In my chrome console i get "Uncaught SyntaxError: Unexpected token :" in the searchJSON object.
Related
i use laravel 5.8 and i have a a problem if i insert or update a page than i go not back to the page list.
postcontroller :
i use : return response()->json('Post Created');
and i use a ajax file whit this code :
$.ajax({
type: 'POST',
url: this.action,
data: new FormData(this),
dataType: 'json',
contentType: false,
cache: false,
processData:false,
success: function(response){
Sweet('success',response)
success(response)
},
error: function(xhr, status, error)
{
$('.errorarea').show();
$.each(xhr.responseJSON.errors, function (key, item)
{
Sweet('error',item)
$("#errors").html("<li class='text-danger'>"+item+"</li>")
});
errosresponse(xhr, status, error);
}
})
});
i get a nice message if it is insert or updated but it not go back to my list, hope you understand what i mean.
if you want to redirect after success do something like this:
$.ajax({
type: 'POST',
url: this.action,
data: new FormData(this),
dataType: 'json',
contentType: false,
cache: false,
processData:false,
success: function(response){
Sweet('success',response)
success(response)
window.location.href = "url you want to redirect to";
},
error: function(xhr, status, error)
{
$('.errorarea').show();
$.each(xhr.responseJSON.errors, function (key, item)
{
Sweet('error',item)
$("#errors").html("<li class='text-danger'>"+item+"</li>")
});
errosresponse(xhr, status, error);
}
})
});
Writing a parse.cloud code to read cross domain xml.
I have tried using jquery-ajax but am stuck with syntactical issue my code is
Parse.Cloud.define("read", function(request, response) {
var query = 'http://data.gov.in/sites/default/files/Date-Wise-Prices-all-Commodity.xml&callback=?';
$.ajax({
url: query,
type: 'GET',
dataType: 'json',
success: function(s) {
response.success("Success");
},
error: function(e)
{
response.success("Error "+e)
}
});
});
I am getting following error :
"code":141,"error":"ReferenceError: $ is not defined\n at main.js:5:20
Use Parse.Cloud.httpRequest
Parse.Cloud.httpRequest({
url: 'http://data.gov.in/sites/default/files/Date-Wise-Prices-all-Commodity.xml',
success: function(httpResponse) {
// httpResponse.data will hold the returned object
},
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
}
});
https://www.parse.com/docs/cloud_code_guide#networking
https://parse.com/docs/js/symbols/Parse.Cloud.HTTPResponse.html
$.ajax({
type: 'GET',
url: 'http://api.xhanch.com/islamic-get-prayer-time.php?lng=34.4366455078125&lat=31.48957771850194&yy=2013&mm=5&gmt=3&m=json',
dataType: 'jsonp',
success: function () {
console.log('Success!');
},
error: function () {
console.log('Uh Oh!');
},
jsonp: 'jsonp'
});
when I run this code I get an error in the return json object
Uncaught SyntaxError: Unexpected token:
Why?
The problem is jsonp: 'jsonp' is calling the method jsonp that doesn't exist in your code. If you really need this, just create the method or remove it.
Remove
$.ajax({
type: 'GET',
url: 'http://api.xhanch.com/islamic-get-prayer-time.php?lng=34.4366455078125&lat=31.48957771850194&yy=2013&mm=5&gmt=3&m=json',
dataType: 'jsonp',
success: function () {
console.log('Success!');
},
error: function () {
console.log('Uh Oh!');
},
});
Or create the method
$.ajax({
type: 'GET',
url: 'http://api.xhanch.com/islamic-get-prayer-time.php?lng=34.4366455078125&lat=31.48957771850194&yy=2013&mm=5&gmt=3&m=json',
dataType: 'jsonp',
success: function () {
console.log('Success!');
},
error: function () {
console.log('Uh Oh!');
},
jsonp: { jsonp: false, jsonpCallback: "callbackName" }
});
function callbackName(){
/*do something*/
}
Reference: http://api.jquery.com/jQuery.ajax/
jsonp
Type: String Override the callback function name in a jsonp request.
This value will be used instead of 'callback' in the 'callback=?' part
of the query string in the url. So {jsonp:'onJSONPLoad'} would result
in 'onJSONPLoad=?' passed to the server. As of jQuery 1.5, setting the
jsonp option to false prevents jQuery from adding the "?callback"
string to the URL or attempting to use "=?" for transformation. In
this case, you should also explicitly set the jsonpCallback setting.
For example, { jsonp: false, jsonpCallback: "callbackName" }
I'm trying to crate a code that will get some info about a movie using some IMDB API, but I'm getting two errors that I can't fix...
This is the code:
<body>
<h1>The bourne Legacy</h1>
<h2>2012</h2>
<script>
(function() {
function getMovieInfo( title, year ) {
$.ajax({
type : 'GET',
url: "http://www.deanclatworthy.com/imdb/",
dataType: 'jsonp',
data: { 'q': title, 'year': year },
success: function(info) {
console.log(info.year);
}
});
}
getMovieInfo( $('h1').text(), $('h2').text() );
})();
</script>
</body>
and the errors are the next:
Resource interpreted as Script but transferred with MIME type text/html: "http://www.deanclatworthy.com/imdb/?callback=jQuery18108839007553178817_1347625688866&q=The+bourne+Legacy&year=2012&_=1347625688869". jquery.min.js:2
Uncaught SyntaxError: Unexpected token : www.deanclatworthy.com:1
function getMovieInfo( title, year ) {
$.ajax({
type : 'GET',
url: "http://www.deanclatworthy.com/imdb/",
dataType: 'json',
data: { 'q': title, 'year': year },
success: function(info) {
console.log(info.year);
}
});
}
getMovieInfo( $('h1').text(), $('h2').text() );
});
I am trying to call to a different document to get the phone number. Unfortunately, it does not appear to be working properly and won't pull the correct phone number. Is there a way I can just set the phone number in the code? Currently my code looks like this:
function setTollNo() {
$.ajax({
type: "POST",
url: "/PURLService.asmx/GetTollNo",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(html) {
$("[id*=tollNo]").html(html.d);
},
error: function() { alert('error'); }
});
}
Would I be able to put something along the lines of the following?
tollNo = 18005557755
I think you are looking for
function setTollNo() {
$.ajax({
type: "POST",
data: { tollNo: '18005557755' },
url: "/PURLService.asmx/GetTollNo",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(html) {
$("[id*=tollNo]").html(html.d);
},
error: function() { alert('error'); }
});
}
Go to the jQuery.ajax docs and search for "Examples".