how ajax site wide browsing works on phpfox? - ajax

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&param2=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

Related

My jquery and ajax call is not responding and showing unexpected error in console

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/>")

Change route running

I've created this route: Home / PaginaBase.
This route is called a new page, called PaginaBase, which has a similar header and footer Index. This creates a footer menu.
When I select an item from this menu, he calls me PaginaBase riding a URL like this:
http://www.localhost:58686/Home/PaginaBase/6/3.
Until then, it's ok. When I select another item (PaginaBase still inside), it retains the same URL in the call and adds Home/PaginaBase/8/3 again, there is a non-existent route.
How do I solve this?
Below is my jquery function.
function MontaMenuInferior() {
var str = "";
$.ajax({
url: '/Home/MontaMenuInferior',
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "POST",
success: function (data) {
$(data.resultado).each(function () {
str = str + '<ul class="grid_4">' +
'<li>' + this.SubCategoria + '</li>';
$(this.subconsulta).each(function () {
if (this.Id_SubCategoria2 != null)
str = str + '<li>' + this.SubCategoria2 + '</li>';
//str = str + '<li>this.SubCategoria2 + ''
else
str = str + '<li>' + this.SubCategoria2 + '</li>';
});
str = str + '</ul>';
$('#menufooter').append(str);
str = "";
});
},
error: function (error) {
}
});
}
You're using relative URLs in your links. If you're in /Home/PaginaBase/6/3 (i.e. that's your path) and you click a link to Home/PaginaBase/8/3 your new path will be /Home/PaginaBase/6/3/Home/PaginaBase/8/3.
Using absolute URLs will replace your path instead of appending to it: /Home/PaginaBase/8/3 (notice the / in the beginning).

How to make XMLHttpRequest work over HTTPS on google chrome?

I researched about this a lot, but couldn't find the magic.
Actually I want to populate a list of city pin code no. using JQuery autocomplete UI. It's a https page. It's working in Firefox but not in Google Chrome. Can anyone help me to resolve this issue. Thanks in Advance.
In the following is my code:
function zipAutoCompletet(prefix) {
jQuery("#" + prefix + "_zip").autocomplete({
source: function(request, response) {
jQuery.ajax({
url: "http://ws.geonames.org/postalCodeSearchJSON",
dataType: "jsonp",
data: {
style: "full",
maxRows: 12,
postalcode_startsWith: request.term
},
success: function(data) {
response(
jQuery.map(data.postalCodes, function(item) {
return {
label:
item.placeName +
(item.adminCode1
? ", " + item.adminCode1
: "") +
", " +
item.postalCode +
", " +
item.countryCode,
value: item.postalCode
};
})
);
jQuery(".ui-autocomplete").css("width", "188px");
}
});
},
minLength: 2,
select: function(event, ui) {
var myString = new String(ui.item.label);
var address = myString.split(",");
jQuery("#" + prefix + "_city").val(address[0]);
jQuery("#" + prefix + "_city").addClass("activated");
jQuery("#" + prefix + "_city").trigger("change");
jQuery("#" + prefix + "_city")
.parents(".row")
.removeClass("error-row");
jQuery("#" + prefix + "_city")
.parents(".row")
.addClass("ok-row");
var countryCode = address[3] ? address[3] : address[2];
countryCode = jQuery.trim(countryCode);
var countryName = jQuery(
"#" +
prefix +
'_country option[value="' +
jQuery.trim(countryCode) +
'"]'
).text();
jQuery("#countryContainer .jqTransformSelectWrapper span").html(
countryName
);
jQuery("#countryContainer .jqTransformSelectWrapper").addClass(
"selected-jqtranform"
);
jQuery("#" + prefix + "_country")
.parents(".row")
.addClass("ok-row");
jQuery("#" + prefix + "_country")
.parents(".row")
.removeClass("error-row");
jQuery("#" + prefix + "_country").val(jQuery.trim(countryCode));
var stateCode = address[2] ? address[1] : "";
stateCode = jQuery.trim(stateCode);
if (countryCode == "US") {
var base = base_url;
base = base.replace("https", "http");
jQuery.ajax({
url: base + "/getStateName",
dataType: "jsonp",
data: { stateCode: stateCode },
success: function(data) {
stateName = data;
jQuery("#jc_state").val(stateName);
jQuery("#jc_state").addClass("activated");
jQuery("#jc_state")
.parents(".row")
.removeClass("error-row");
jQuery("#jc_state")
.parents(".row")
.addClass("ok-row");
jQuery("#jc_state").trigger("change");
formValidate();
}
});
} else {
stateName = stateCode;
jQuery("#jc_state").val(stateName);
jQuery("#jc_state").addClass("activated");
jQuery("#jc_state")
.parents(".row")
.removeClass("error-row");
jQuery("#jc_state")
.parents(".row")
.addClass("ok-row");
jQuery("#jc_state").trigger("change");
formValidate();
}
jQuery("#" + prefix + "_zip")
.parents(".row")
.addClass("ok-row");
jQuery("#" + prefix + "_zip")
.parents(".row")
.removeClass("error-row");
},
open: function() {
jQuery(this)
.removeClass("ui-corner-all")
.addClass("ui-corner-top");
},
close: function() {
jQuery(this)
.removeClass("ui-corner-top")
.addClass("ui-corner-all");
},
change: function(event, ui) {
if (ui.item === null) {
jQuery("#" + prefix + "_zip")
.parents(".row")
.removeClass("ok-row");
jQuery("#" + prefix + "_zip")
.parents(".row")
.addClass("error-row");
$("#" + prefix + "_zip").val("");
}
}
});
}
If you are on https page, browser will block requests to non-secure resources (http).
Regularly you should see some notification about that. Looks like other browsers does not block non secure AJAX requests on secured pages by default, but google chrome does.
In your code, you have hardcoded URL:
url: "http://ws.geonames.org/postalCodeSearchJSON",
If that is cross domain request and it supports HTTPS, you can change it like this:
url: "//ws.geonames.org/postalCodeSearchJSON",
As you can see, protocol is not specified there. Browser will take page default protocol (http or https) and use it to request data.

passing parameters containing # in URL for calling webservice using AJAX

I am calling one of my webservice in which im sending some paramters like key,id,subject line,etc
example:
http://asv.msdasmafetrix.net/public/mobile.ashx?method=getparsedtemplate_contactinfo&emailbody='" + emailbody + "'&subjectline='" + subjectline + "'&contactemailid=" + contactemailid + "&id=" + jasondata.id + "&key=" + jasondata.key
but,in parameters like subject and emailbody # variable is present due to which it is breaking my code.and giving me undefined value.i have even tried encodeURI.got no success though.
my code is:
var uri="http://asv.msdasmafetrix.net/public/mobile.ashx?method=getparsedtemplate_contactinfo&emailbody='" + emailbody + "'&subjectline='" + subjectline + "'&contactemailid=" + contactemailid + "&id=" + jasondata.id + "&key=" + jasondata.key";
$.ajax({
type: "GET",
url: encodeURI(uri),
success: function(msg) {
jasondata = eval('(' + msg + ')');
var subjectline = jasondata.subjectline;
alert(subjectline);
}
});
any help ...!!
Try using encodeURIComponent(uri)
Documentation for encodeURIComponent

ajax type:"GET" works for firefox and chrome but not for IE

Hey guys this works for Firefox and Chrome in that it passes the data fine and shows the confirmationpage
but when i run it on IE it just refreshes the page and the data is all NULL while passing
var dataString = 'firstname=' + firstname + '&lastname=' + lastname + '&areacode=' + areacode + '&phonenumber=' + phonenumber + '&emailaddress=' + emailaddress + '&confirmemail=' + confirmemail + '&password=' + password + '&streetaddress=' + streetaddress + '&streetaddress2=' + streetaddress2 + '&city=' + city + '&state=' + state + '&zipcode=' + zipcode + '&month=' + month + '&day=' + day + '&year=' + year + '&services=' + services + '&agreement=' + agreement;
//alert(dataString);
// alert(services);
//var d = new Date();
$.ajax({
// cache: false,
type: "GET",
url: "http://www.vectorcreditsolution.com/js/process.php",
data: dataString,
// dataType: ($.browser.msie) ? "text" : "xml",
success: function(data) {
window.location.href ="thankyou.html";
}
});
return false;
});
1) Have you verified what is arriving at your server (maybe populate a session variable) to ensure your $.ajax() is sending what you think it is?
2) Have you tried
var dataString = $("#formId").serializeArray();
(assuming <form id="formId"...)? And then use that for your data:dataString, element
3) I would expect you would want code something on the server when it is done processing to respond back to your calling page, and then in the success:function(retData) evaluate retData to interpret the server's response. If you simply don't care what happens and just want the browser page to march blindly forward to your thankyou.html upon completion of the ajax call, you don't need to include an argument variable in the function:
success: function() {...},

Resources