Here's a very simple jQuery example :
http://www.ihaols.com/geo.html
Code :
$(function(){
$('#btn').click(function(){
var address = encodeURIComponent($('#k').val());
$.get('http://maps.google.com/maps/api/geocode/json?address='+ address + '&sensor=false', function(data){
console.log(data);
var l = data.results[0].geometry.location;
var v = l.lat + ',' + l.lng;
$('#r').val(v);
});
});
});
But this code doesn't work in IE7/8, I've already include json2.js in it.
Related
I want to clear my previous ajax response images before appending new images please help me how can i do that ? thank u.
Ajax
<script>
$(document).ready(function(){
var preloaded = [];
$(document).on('click','.editBtn',function(){
var marchandiseId = $(this).data("id");
var file ="{{Config('wfh.file')}}";
$(".input-images-edit").empty();
$("#editModel").modal('show');
var url = "{{URL('/marchandise/edit/')}}";
$.ajax({
type:"GET",
url: url + '/' + marchandiseId,
dataType:'JSON',
success:function (response){
var data = response.marchandise.marchandise_details;
$.each(data, function(i, item) {
preloaded.push({id: item.id, src: file + '' + item.images });
});
$('.input-images-edit').imageUploader({
preloaded: preloaded,
imagesInputName: 'photos',
preloadedInputName: 'old'
});
}
});
});
i want a url like this , http://localhost/myproject/get-dishes/1
here is my ajax request code
$('#MainDropDown').change(function(e){
var cid = $(this).val();
e.preventDefault();
$.getJSON("{{url('get')}}/"+cid+" ",
function(data) {
var model = $('#dishDropDown');
model.empty();
$.each(data, function(index, element) {
model.append("<option value='"+element.id+"'>" + element.sub_cate_name + "</option>");
});
});
});
expected result:
http://localhost/teraso/public/get-dishes/1
showing:
http://localhost/teraso/public/add/%7%get-dishes/%D1
Try another alternative way like route() or to() function.
try this..
let url = "{{route('get',[':id-url'])}}";
url = url.replace(':id-url', $(this).val());
then, parse it to ajax
$.getJSON(url, function(data) {
var model = $('#dishDropDown');
model.empty();
$.each(data, function(index, element) {
model.append("<option value='"+element.id+"'>" + element.sub_cate_name + "</option>");
});
});
I'm able to parse JSON with ajax, but at the moment it shows all the names out of the JSON.
I want only one name viewed and after an amount of time I want another one viewed and so on..
Ajax code:
$(document).ready(function(){
parseJson();
});
function parseJson(){
$.ajax({
url : 'data/members.json',
dataType : 'json',
success : function(data) {
succes(data);
},
error: function(){
window.alert("error");
}
});
};
function succes(dataObj){
var counter = 1;
$.each(dataObj.Members.Member, function(indexData, valueData){
var htmlString = "";
htmlString += '<article class="memberInfo" data-object="' + counter + '">';
htmlString += "<div class=''><p>" + valueData.Firstname + ' ' + valueData.Surname + "</p></div>";
htmlString += "</article>";
$("#members").append(htmlString);
counter++;
});
}
Rather than use .append you can use .html and set a staggering timeout so that it cycles through the names that get displayed:
var timer = 0;
$.each(...
setTimeout(function () {
var htmlString = "";
/* snip */
$("#members").html(htmlString);
}, timer + (indexData * 2000));
});
I'm trying to do an exercise where I need to have an AJAX feed for my webpage. As my website is about books I'm using the Google Books API.
I cant figure out how to show the title of the book though. This is the code I have so far:
$(document).ready(function(){
var url = 'https://www.googleapis.com/books/v1/volumes?q=:a';
$.get(url, function(data,status){
console.log(data);
var intValue =data.totalitems;
var strOne =data.kind;
var items = data.items;
$.each(items, function( index, value) {
console.log(value.title);
$('#div1').append('<li><div>'+value.title+'</div></li>') });
});
});
});
Try the following
JS
$.each(data.items, function(entryIndex, entry){
var html = '<div class="results">';
html += '<h3>' + ( entry.volumeInfo.title || '' )+ '</h3>';
$(html).hide().appendTo(".result");
});
html
<div class="result"></div>
folks
we are facing a strange issue with jquery ( 1.8.3) and we are using cakePHP
as per the image
Our assumption is we are sending the data( about 500 +) with ajax call in POST method.
we are having this issue in all the major browsers.
as above( in chrome) , we are getting this error in console we passed 618 destinations in ajax call.
let us know the work around to solve this problem.
My ajax call is as below
function validate_test() {
$("#btn1").empty();
var ele = document.getElementById('frm_searchDateFrom').value;
var ele2 = document.getElementById('frm_searchDateTo').value;
var sub_url = '<?php echo $this->Html->url('/', true); ?>';
var url = sub_url + "admin/reports/check_originator/" + ele +"/"+ ele2 +"/"+ $("#destination").val();
alert(url);
jQuery.ajax({
type: "POST",
datatype: "json",
url: url,
success: function(data)
{
var el = $("select#btn1").multiselect();
var d;
var results=data.split(",");
for(d=0;d<results.length;d++) {
var d;
var v = results[d], opt = $('<option />', {
value: v,
text: v
});
opt.appendTo( el );
el.multiselect('refresh');
}
}
})
}
In your JQuery Ajax method instead of posting all those details as url query para meter send by wrapping those details in a object.
function validate_test() {
$("#btn1").empty();
var ele = document.getElementById('frm_searchDateFrom').value;
var ele2 = document.getElementById('frm_searchDateTo').value;
var sub_url = '<?php echo $this->Html->url('/', true); ?>';
var url = sub_url + "admin/reports/check_originator/";
var formdata=ele +"/"+ ele2 +"/"+ $("#destination").val();//put form data's in an object
alert(url);
jQuery.ajax({
type: "POST",
datatype: "json",
data:formdata,//send the form data object in post
url: url,
success: function(data)
{
var el = $("select#btn1").multiselect();
var d;
var results=data.split(",");
for(d=0;d<results.length;d++) {
var d;
var v = results[d], opt = $('<option />', {
value: v,
text: v
});
opt.appendTo( el );
el.multiselect('refresh');
}
}
})
}
Also refer this fiddle(not mine):
http://jsfiddle.net/clickthelink/Uwcuz/1/