|
Page 1 of 1 |
|
Posted: Fri, 21st Nov 2014 18:21 Post subject: Learning AJAX |
|
 |
Any good sources and tutorials on learning AJAX?
I will kinda have to make a shortcode for a plugin for wordpress (my boss has the portfolio plugin that's bundled up with his themes, and an existing portfolio shortcode).
Basically I have to recreate a functionality from one site (I forgot the name of it of course), where you click on a picture and underneath it you get the picture details (that you set in portfolio).
My boss could probably do it in a few hours (he's really good at coding), but I'd like to learn more, as it will help me advance
So any tutorials, sites, books will be helpful 
"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson chiv wrote: | thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found. |
|
|
Back to top |
|
 |
|
Posted: Fri, 21st Nov 2014 18:24 Post subject: |
|
 |
Are you using any framework?
Angular?
jQuery?
With jQ you can do some easy ajax loading with something as easy as:
Code: |
$('#targetdiv').load('random_quote.php');
|
|
|
Back to top |
|
 |
|
Posted: Sat, 22nd Nov 2014 10:09 Post subject: |
|
 |
Just jQuery. The shortcode is written in php.
If I understand it, I should use GET method to get the data from each individual object. Then I create the look of the shortcode in php, and use AJAX to load stuff when clicked.
One thing that concerns me, I can load files to desired place, but that will load the styling as well. What if I need only parts of it?
For instance, when you click and go to single portfolio (governed in wordpress by single-portfolio.php), inside are, besides images, description and some other fields, the ability to create a whole page underneath it. And I don't really need that. I have no idea how to pull only the things I want from each item :S
So I need some instructions to learn how to do that.
"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson chiv wrote: | thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found. |
|
|
Back to top |
|
 |
|
Posted: Sat, 22nd Nov 2014 10:18 Post subject: |
|
 |
Code: | $.get('data_source.php', {
parameter1: "value1",
parameter2: "value2
}).done(function(data){
$('#target').text(data);
//ajax request succeeded and returned the data in the data variable
}).fail(function(){
alert("shit's fucked up");
//well something went wrong
}).always(function(){
console.log('I want to be with you. Make believe with you and live in harmony harmony oh love');
//no matter if it fails or succeeds, this is going to be executed oh love
}); |
If the page that you retrieve is another html page, then you can just access the data this way:
Code: |
$.get('page.php').done(function(data){
$(data).find('#thedivispendmywholelifesearchingfor').appendTo('#thisiswheretheajaxshitlands');
});
|
|
|
Back to top |
|
 |
|
Posted: Sat, 22nd Nov 2014 19:47 Post subject: |
|
 |
I can access the parts of html using jquery as I usually do with .find() .parents() etc.? If so, that shouldn't be a problem, no?
"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson chiv wrote: | thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found. |
|
|
Back to top |
|
 |
|
Posted: Sat, 22nd Nov 2014 22:07 Post subject: |
|
 |
yeah, as I showed in the second example, I assume that the result of page.php is some html page and with $(data) I transform it into a jQuery object which enables you to use the standard jQuery functions like find and so on on it.
|
|
Back to top |
|
 |
|
Posted: Sun, 23rd Nov 2014 11:17 Post subject: |
|
 |
Cool It doesn't sound that hard 
"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson chiv wrote: | thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found. |
|
|
Back to top |
|
 |
|
Posted: Tue, 25th Nov 2014 14:14 Post subject: |
|
 |
|
|
Back to top |
|
 |
|
Posted: Tue, 25th Nov 2014 18:10 Post subject: |
|
 |
Didn't test it yet, I have to fix tons of bugs and fix the stupid woocommerce on another theme, so when I'm done with that I'll be doing the AJAX one 
"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson chiv wrote: | thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found. |
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group
|
|
 |
|