I have the following code to call a ajax POST :
$("a[href=Save]").click(function() {
var thisform = $(this).attr("name");
// Get all the information left in the form
var lname = $('div[name="' + thisform + '"] input[name="lname"]').val();
var fname = $('div[name="' + thisform + '"] input[name="fname"]').val();
var mname = $('div[name="' + thisform + '"] input[name="mname"]').val();
var language = $('div[name="' + thisform + '"] input[name="lang"]').val();
var title = $('div[name="' + thisform + '"] input[name="title"]').val();
var ptype = $('div[name="' + thisform + '"] input[name="ProfileType"]').val();
var vip = $('div[name="' + thisform + '"] input[name="VIP"]').val();
var vreason = $('div[name="' + thisform + '"] input[name="Vreason"]').val();
alert (lname);
//Set the Ajax Request
$.post("..\ajax\profileMod.php", {
'lname':lname,
'fname':fname,
'mname':mname,
'language':language,
'title':title,
'ptype':ptype,
'vip':vip,
'vreason':vreason
};
.done(function(data) {
// php code : echo json_encode(array("name"=>"Called!"));
alert(data.name);
});
// Stop original behavior
return false;
});
I don't know where I went wrong but the code is not working. I'm trying to call a php file using the POST, and showing a message to see if the file got called correctly. All my "var" are getting to right value (I've tested all of them one by one).
I've look at so many post to find the error that my eyes hurt! So I'm asking help!!!
Thank you!
looks like you put a ";" where you should have put a ")"
'vip':vip,
'vreason':vreason
}; <-- problem
.done(function(data) {
// php code : echo json_encode(array("name"=>"Called!"));
alert(data.name);
Should be
'vip':vip,
'vreason':vreason
}) <-- fix
.done(function(data) {
// php code : echo json_encode(array("name"=>"Called!"));
alert(data.name);
i think
Related
I don't know why my code is giving error while making the ajax call and not responding or working at all. I ran this on an html file. I took this function - getParameterByName() from another stackoverflow answer.tweet-container tag is down the code below outside this script and an empty division.I tried some jquery also.
<script>
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
$(document).ready(function(){
console.log("working");
var query = getParameterByName("q")
// console.log("query");
var tweetList = [];
function parseTweets(){
if (tweetList == 0){
$("#tweet-container").text("No tweets currently found.")
} else {
//tweets are existing, so parse and display them
$.each(parseTweets, function(key, value){
//console.log(key)
// console.log(value.user)
// console.log(value.content)
var tweetKey = value.key;
var tweetUser = value.user;
var tweetContent = value.content;
$("#tweet-container").append(
"<div class=\"media\"><div class=\"media-body\">" + tweetContent + "</br> via " + tweetUser.username + " | " + View + "</div></div><hr/>"
)
})
}
}
$.ajax({
url:"/api/tweet/",
data:{
"q": query
},
method: "GET",
success:function(data){
//console.log(data)
tweetList = data
parseTweets()
},
error:
function(data){
console.log("error")
console.log(data)
}
})
});
</script>
strong text
Fix the quotes to resolve your syntax error:
$("#tweet-container").append("<div class=\"media\"><div class=\"media-body\">" + tweetContent + " </br> via " + tweetUser.username + " | " + "View</div></div><hr/>")
I want to parse the below mentioned RSS in order to get the title, description, image and date. Currently i'm able to get the all other details except image. Im using google api feed to parse the rss. Please can anyone me in this context.
RSS:https://news.google.com/news/feeds?cf=all&ned=in&hl=en&q=cricket&output=rss
// Google Feed API: https://developers.google.com/feed/
// Inspiration: http://designshack.net/articles/javascript/build-an-automated-rss-feed-list-with-jquery/
function parseFeed(url, container) {
$.ajax({
url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=5&callback=?&q=' + encodeURIComponent(url),
dataType: 'json',
success: function (data) {
// log object data in console
console.log(data.responseData.feed);
// append feed link and title in container
$(container).append('<span class="iconicstroke-rss-alt"></span>');
$(container).append('<h1 class="feed">' + data.responseData.feed.title + '</h1>');
// for each entry... *
$.each(data.responseData.feed.entries, function (key, value) {
// * create new date object and pass in entry date
var date = new Date(value.publishedDate);
// var thumbnail = entry.mediaGroups[0].contents[0].url;
// * create months array
var months = new Array(12);
months[0] = 'January';
months[1] = 'February';
months[2] = 'March';
months[3] = 'April';
months[4] = 'May';
months[5] = 'June';
months[6] = 'July';
months[7] = 'August';
months[8] = 'September';
months[9] = 'October';
months[10] = 'November';
months[11] = 'December';
// * parse month, day and year
var month = date.getMonth();
var day = date.getDate();
var year = date.getFullYear();
// * assign entry variables
var title = '<h3 class="title">' + value.title + '</h3>';
var time = '<p class="time">' + months[month] + ' ' + day + ', ' + year + '</p>';
var snippet = '<p class="snippet">' + value.contentSnippet + '</p>';
var img = '<p class="snippet">' + value.thumbnail + '</p>';
var entry = '<div class="entry">' + title + time + snippet + '</div>';
// * append entire entry in container
$(container).append(entry);
});
},
// if there's an error... *
error: function (errorThrown) {
// * log error message in console
console.log(errorThrown);
// * show error message
alert('Houston, we have a problem.');
}
});
}
$(document).ready(function () {
parseFeed('https://news.google.com/news/feeds?pz=1&cf=all&ned=en&hl=in&q=aishwarya%20rai&output=rss', '#csstricks');
});
Just add this to your script
var content = document.createElement("content");
content.innerHTML = value.content;
var images = "";
$(content).find('img').each(function() {
images += this.outerHTML;
});
var img = '<p class="snippet">' + images + '</p>';
Same answer as here: https://stackoverflow.com/a/26369373/989257
Codepen example: http://codepen.io/janih/pen/JdPMZX
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 use ajax wide browsing on phpfox but i dont understand how it works,
any idea please ?
i found in static/jscript/main.js this code :
$Core.ajax = function(sCall, $oParams)
{
var sParams = '&' + getParam('sGlobalTokenName') + '[ajax]=true&' + getParam('sGlobalTokenName') + '[call]=' + sCall;
if (!sParams.match(/\[security_token\]/i))
{
sParams += '&' + getParam('sGlobalTokenName') + '[security_token]=' + oCore['log.security_token'];
}
if (isset($oParams['params']))
{
if (typeof($oParams['params']) == 'string')
{
sParams += $oParams['params'];
}
else
{
$.each($oParams['params'], function($sKey, $sValue)
{
sParams += '&' + $sKey + '=' + encodeURIComponent($sValue) + '';
});
}
}
$.ajax(
{
type: (isset($oParams['type']) ? $oParams['type'] : 'GET'),
url: getParam('sJsStatic') + "ajax.php",
dataType: 'html',
data: sParams,
success: $oParams['success']
});
};
I'm trying to fix a module of chat while browsing on my site
Any idea plz ?
To make a link for site wide ajax browsing you do it just like usual, phpfox will figure it out for you.
If you want to make an ajax call in phpfox you do:
$.ajaxCall('module.function', 'param1=value1¶m2=value2');
for example:
$.ajaxCall('ad.recalculate', 'total=' + iTotal + '&location=' + sLocation + '&block_id=' + sBlockId + '&isCPM=' + $Core.Ad.isCPM);
Calls the function recalculate in the file /module/ad/include/component/ajax/ajax.class.php and passes the params: total, location, block_id and isCPM
Hello friends,
I am developing an app using Google Place API in Titanium Development and successfully got data and display in tableview and add button in each row but my issue is that I want to get name and address on button click in each row so please give me idea or any link to solve my issue.
Please take a look in my screenshot so on btnclick I want to get name and address.
Thanks in advance.
var categoryName;
var addressLabel;
var row;
var tableData=[];
PlacesListCells = function createRow()
{
//var tableData=[];
var loader = Titanium.Network.createHTTPClient();
var url = "https://maps.googleapis.com/maps/api/place/search/json?";
url = url + "location=" + lat + ',' + lon;
url = url + "&radius=" + radius;
url = url + "&name=" + name;
url = url + "&sensor=" + sensor;
url = url + "&key=" + key;
Ti.API.info(url);
// Sets the HTTP request method, and the URL to get data from
loader.open("GET",url);
// Create our HTTP Client and name it "loader"
// Runs the function when the data is ready for us to process
loader.onload = function()
{
var obj = JSON.parse(this.responseText);
Ti.API.log(obj);
var results = obj.results;
Ti.API.log(results);
for (var i = 0; i < results.length; i++)
{
categoryName = obj.results[i].name;
reference = obj.results[i].reference;
Ti.API.log('Refernce:'+reference);
// Create a row and set its height to auto
row = Titanium.UI.createTableViewRow({height:'78'});
var placeImage = Titanium.UI.createImageView
({
image:'../iphone/appicon.png',
width:70,
height:50,
top:12,
left:5
});
// Create the label to hold the tweet message
var nameLabel = Titanium.UI.createLabel({
//text:name,
left:80,
top:5,
height:'auto',
width:185,
textAlign:'left',
font:{fontSize:12}
});
// Create the label to hold the tweet message
addressLabel = Titanium.UI.createLabel({
left:80,
top:25,
height:'auto',
width:185,
textAlign:'left',
font:{fontSize:14}
});
var arrowImage = Ti.UI.createImageView
({
image:'../iphone/appicon.png',
width:20,
height:20,
left:280,
top:30
});
var favoriteButton = Ti.UI.createButton
({
title:'btn',
//font:{fontFamily:'Helvetica Neue',fontSize:15},
top:20,
left:255,
height:30,
width:50,
url:'../Images/favorite.png'
//image:'../Images/favorite.png'
});
nameLabel.text = categoryName;
getDetailsData(addressLabel,row,i);
row.add(placeImage);
row.add(nameLabel);
row.add(addressLabel);
row.add(favoriteButton);
//row.add(arrowImage);
tableData[i] = row;
//set page title for each row
row.pageTitle = nameLabel.text;
favoriteButton.row = i;
favoriteButton.addEventListener('click', function(e)
{
Ti.API.log('favoriteButton clicked on row ' + e.source.row +' at ' + new Date().getSeconds());
alert('favoriteButton clicked on row ' + e.source.row);
var index = e.source.row;
var name = tableData[index];
alert('name'+name);
});
}
tableView.setData(tableData);
};
//-- Network error
loader.onerror = function(e)
{
Ti.API.info('Network error: ' + JSON.stringify(e));
};
// Send the HTTP request
loader.send();
return tableData;
};
Once you have your index, you should be able to reference your original data source by that.
var favoriteButton = Ti.UI.createButton({
title:'btn',
//font:{fontFamily:'Helvetica Neue',fontSize:15},
top:20,
left:255,
height:30,
width:50,
url:'../Images/favorite.png'
//image:'../Images/favorite.png',
name:categoryName,
address:address;//address mention here
});
row.add(favoriteButton);
favoriteButton.addEventListener('click', function(e)
{
var index = e.source.row;
var name = e.source.name;
var address = e.source.address;
alert('name'+name);
});
}
I think this might help you a lot.