jQuery AJAX URL change Phonegap - javascript

How do I change the URL in Ajax and reload page with new content?
I make a service in WP: www.test.com/page/?u=test
$_GET['u'];
and while(..... new information) works good.
But I have a problem with this..
$('#test').click(function(){
uel = "http://......com/servisi302/?u=zanimljivosti";
$('#page-content').hide(1000);
$('#page-content').show(1000);
alert(uel);
return false;
});
jQuery.ajax({
url : '' +uel,
type : "POST",
dataType : "json",
data : "param=no",
success : function(html){
var QUERY = jQuery(".query");
console.log(html);
jQuery.each(html, function(key, value){
console.log(value);
QUERY.append("<div class='media well'><a href='#' class='pull-left'><img width='64' height='64' src='" + value.slika + "'class='media-object' alt='' /></a><div class='media-body'><h4 class='media-heading'><p>" + value.naslov + "</p></h4></div></div>");
});
}, error : function(e){
alert(e);
}
});
});
How do I change the URL or variable and subsequently reload with the new content?

Related

Download Base64 image through javascript

I am working on an image panel that displays the image titles and a link to download the image. I have an onclick function that gathers the base64 data from the database and then 'decodes' it. However, when I decode it I'm getting back a string of Chinese text..which is obviously not what I'm looking for.
$(document).ready(function() {
$('.downloadAttachment').on('click', function() {
var documentId = $(this).attr("data-id");
console.log(documentId)
$.ajax({
dataType: 'json',
//data: id,
async: false,
type: 'GET',
//url: baseUrl + 'rest/incdDocument/getAll?branchCode=' + brCode + '&receivedDate=' + receiveDate + '&complaintID=' + cId + '&incidentID=' + incidentId+ '&documentID='+documentId,
url: baseUrl + 'rest/incdDocument/get?branchCode=009&receivedDate=03/10/2017&complaintID=170&incidentID=3'+'&documentID='+documentId,
success: function(data) {
if (data) {
var image = Base64.decode(data.data);
window.open(image, '_blank');
}
},
error: function(request, status, error) {
console.log(error)
}
});
return false;
})
});
Is there a better way to extract this data and actually turn it into an image?
Searching for like this ?
var image = new Image();
image.src = data; (complete base64 sting with imagetype)
Download Image
Make a download.php file with return the a image with
header('Content-type:image/png'); or other image type

How can I access the first image in a feed using Google Feed API?

I'm using the Google Feed API to parse a feed into HTML. I'm trying to access the first image from the content body of the JSON. Here's my script right now:
function parseRSS(url, container) {
$.ajax({
url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + encodeURIComponent(url),
dataType: 'json',
success: function(data) {
console.log(data.responseData.feed);
// $(container).html('<h2>'+capitaliseFirstLetter(data.responseData.feed.title)+'</h2>');
$.each(data.responseData.feed.entries, function(key, value) {
var images = $(value.content).find('img').map(function(){
return $(this).attr('src')
}).get();
$(container).append('<article><h3> '+ value.title +' </h3>'+ ( images.length == 0 ? '' : '<img src="'+ images[0] + '"/>' )+'<p>'+ value.contentSnippet +'</p></article>');
});
}
});
}
function capitaliseFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
It fetches the second image just fine, but not the first. Any suggestions?

Ajax Request on another's success ( jQuery )

I want to run the another ajax request on one's success.
THE CODE
$(document).ready(function(){
$('*[data-load-template]').each( function () {
var template = $(this).data('load-template');
var element = $(this);
$.ajax({
url : "templates/" + template + '.tpl',
method : "GET",
success : function (htmlData) {
$.ajax({
url : "data/" + template + '.json',
method : "GET",
success : function (jsonData) {
console.log(jsonData); // why isn't this one working???
}
});
element.html(htmlData); // this is working
}
});
});
}); // dom ready event
My question is why isn't this code working and how to make it work.

How to reload page using Ajax

I have function addFeaturesToScene which make a new URL using ajax.
After the function ends I need to go to the new site automatically
Here is code:
function addFeatureToScene(featureNid, sceneNid)
{
alert(featureNid + " -> " + sceneNid);
$.ajax({
type : 'GET',
url : '/copy-feature-and-add-it-to-scene/' + featureNid + '/' + sceneNid,
dataType : 'json',
async : false,
success : function(reply) {
//Code to open a page with a new url?
}
});
}
You can use window.location
window.location.href = 'http://example.org';

How to add a variable to URL of $.ajax({ url : " "});

I want the user to be able to change a part of the URL address to their post code. I have a text box and button which I am hoping will submit the value to the URL.
jQuery:
jQuery(document).ready(function($) {
$.ajax({
url : "http://SomeAddress.com/" + PostCode + ".json",
dataType : "jsonp",
success : function(parsed_json) {
HTML:
<input type="text" id="GetPostCode" />
<button id="SetPostCode">Set This Post Code</button>
jQuery:
$("#SetPostCode").click(function() {
var PostCode = document.getElementById("GetPostCode").value;
$("#GetPostCode").val(" ");
return false;
});
I understand that the line
$.ajax({
url : "http://api.wunderground.com/api/2508132ae0c7601a/geolookup/conditions/q/UK/" + PostCode + ".json",
does not work that way, but I didn't know what else to do. Could someone please show me what I need to do in order for this to work?
jQuery(document).ready(function($) {
var PostCode=1;
$.ajax({ url : "http://SomeAddress.com/"+PostCode +".json",
dataType : "jsonp"
//.... more stuff
});
$("#SetPostCode").click(function() {
PostCode = document.getElementById("GetPostCode").value;
$("#GetPostCode").val(" ");
return false;
});
});
Above would work as PostCode is now global to the jQuery and can be accessed anywhere

Categories

Resources