ajax call in joomla 2.5 module - joomla

I like to create a custom module in which I have a select list which on change has to select data from db and show the data.
How can I give the url in the ajax call in my module's helper function?

You create a module with a custom position then you load your module in a new article.
Every article has an ID and an ALIAS.So the url will be like that
http://myurl.gr/ID-ALIAS.html?tmpl=component&type=raw
For more details check the below link:
How to load a custom html module using ajax-call joomla 2.5

You can use something like this :
function datadelete(id){
var dataString = 'id='+ id;
$.ajax({
type: "POST",
url: "index.php?option=componentname&task=deleteecontacts&type=ajax",
data: dataString,
cache: false,
success: function(msg)
});
}
I hope this will give you an idea about how to pass URL in Ajax call using Jquery

Related

How to pass controller action in Jquery AJAX Call in Oxid eSHOP

I am working on Jquery AJAX in OXID eSHOP.
I want to pass proper action (function) name in AJAX url parameter.
Below is my code:
jQuery.ajax({
type: "POST",
data: {
variable: value
},
url: "",
success: function(data) {
}
});
I want to call one function in url parameter.
But don't know how to pass its value in url paramaeter.
Anyone knows then please help me.
You should include function name as URL parameter, just like the shop does it in most situations:
http://your-shop.com/index.php?cl=controller&fnc=functionname

Manually adding google analytic code to different urls through jQuery AJAX

I'm working on a progressive page loading script where new pages will load continuously when bottom of the page is reached. I'm using ajax to fetch the data dynamically through jQuery ajax from the server, the return data will return the url of the new post as well as its content.
My problem is what code should I use to submit my returned post url to analytic so that it registers as a valid page view?
$.ajax({
type: 'GET',
url: 'http://somedomain.com/fetch_pages.php',
data: { 'page': this.$loadMoreCounter , 'section': that.$section },
dataType: 'json',
success: function (data) {
//analytic code upon each successful callback.
});

get data from ajax as an attribute value for callback function

Im new to ajax. I was trying to find the answer but was not lucky to find the corresponsing one. Basically I need to use an ajax to get some data and after that to put this data to the variable that later will be used as an attribute for the callback function with custom code.
This ajax part is just a method of myObject.
So, in the end I need this kind of functionality:
myObject.getData(url, callback(data) {
//my custom code of what I wanna do after ajax is complete
});
My code
/*
HERE COME SOME PROPERTIES AND OTHER METHODS WICH IS NOT THE CASE
*/
//This is where Im stuck
var getData = function getFromUrl($url) {
$.ajax({
type: 'get',
url: $url,
dataType: 'html',
success: function(html) {
$obj = html;//Im lost on this step!
},
});
};
P.S. Im trying to find an async way (without using async:false). Hope its possible
First I encountered many problems. My first problem was No Access-Control-Allow-Origin, most websites dont allow you to just scrap get their data for security reasons. Luckily someone already made a proxy: http://cors.io/ . Second problem is that you cant embed http on https, so I cant use jsfiddle to show you this working, it works on my local enviroment. After you get the raw html you have to parse it, you can do it with full regex, or you can power yourself with jquery like I'm doing on this example. What we're doing is checking stackoverflow.com and getting the amount of featured questions with .find(".bounty-indicator-tab").first().html(); But once you have the full html you can get any data you need.
var getData = function getFromUrl(url) {
$.ajax({
url: 'http://cors.io/?' + url,
crossDomain: true,
dataType: 'html',
success: function (html) {
var match = $(html).find(".bounty-indicator-tab").first().html();
console.log(match);
return match;
},
error: function(e) {
console.log('Error: '+e);
}
});
};
url = 'http://stackoverflow.com/';
data = getData(url);
//You cant use data yet because its working async

Grails: Passing a javascript variable to a template

I am new to ajax so maybe this is obvious. I've tried many different not-working approaches. I have javascript that when you click on a button:
an ajax call that grabs some data from a controller - returns an object
display that data in a template that I will show on the page
Here is the javascript/ajax:
<script type="text/javascript">
$("#show").click(function () {
$.ajax({ url: '/Myproject/result/index',
type: "POST",
data: { id: id},
success: function(result) {
alert("Success:" + result); // Can see getting object back.
}});
$(".resulttable").show();
});
Here is the key line in grails view template:
<g:each in="${allResults}" status="i" var="result">
How do I get the data from the javascript to the gsp code (ie allResults)?
Do I have to "refresh" this template to display new data?
thanks.
You just can't make your javascript/jquery code populate things in the gsp, since the gsp is processed server-side and javascript is processed client-side, after the gsp rendered all html documents and populated them with your model. You need to be aware that your page was already processed, so things like ${variables} won't be reloaded anymore. So when you do this:
$(".resulttable").show();
It's not gonna show the result you're waiting for. You have to use javascript code to reload your result table.
So if you're using ajax here, you should use the function success to alter your html table via javascript/jquery since you already have the response you wanted. Maybe this read can help you. Oh, and I think it would be better if in your ajax call, you would define a dataType (json works great in your case), like this:
$("#show").click(function () {
$.ajax({ url: '/Myproject/result/index',
type: "POST",
data: { id: id},
dataType: 'json',
success: function(result) {
alert("Success:" + result); // Can see getting object back.
}});
$(".resulttable").show();
});
Just to make clear what kind of response you're getting from the controller.
You do not need to write your ajax calls the hard way. There are some Grails intern tags you can use inside your html:
http://grails.org/doc/latest/ref/Tags/remoteFunction.html
http://grails.org/doc/latest/ref/Tags/submitToRemote.html
http://grails.org/doc/latest/ref/Tags/remoteLink.html
Following the links you will find some nice examples...

Ajax with wordpress

I'm make an ajax call to run a file:
var data = 'index=exp' + index;
var go_url = get_bloginfo('template_url') + '/form/exp.php';
$.ajax({
url: go_url,
type: "GET",
data: data,
cache: false
});
The file "exp.php" inserts a new row in mysql database and it works.. but with the ajax call nothing happens. As if he did not open the link.
I think you should add 'add_action' for functions in wordpress
like
function yourfunction(){
...
}
add_action('wp_ajax_your_function', 'yourfunction');
add_action('wp_ajax_nopriv_your_function', 'yourfunction');
and in your jquery you can call 'your_function' instead of php file
Is the ajax being called?
Try putting it inside of document ready.
$(document).ready(function() {
// put all your jQuery goodness in here.
});

Resources