Welcome Guest, Not a member yet? Register   Sign In
change content
#1

[eluser]marcin346[/eluser]
Hello everyone.
I have small question. I need change content using jquery or javascript. I'm writing vote system and i want make: after click vote_up button div, which has for example id="123_vote" will refresh.
How to do it?
Sorry for my language.
#2

[eluser]egunay[/eluser]
Hope this will help you:

First of all I'd suggest you to use jquery as it simplifies your work.

Put a jquery mouse event such as;

$("#vote_up").click(function() { // On click #vote_up
//Here do an ajax request to get the 123_vote's content.
//You should use ajax, load etc. otherwise you can't refresh it. (Or try using iframes)
$.ajax({
url: "your_url_that_returns_123_votes_content",
success: function(data){
$("#123_vote").html(data);
}
});
});
#3

[eluser]marcin346[/eluser]
Thanks, but i want extended version.
Div 123_vote was generated dynamic~~. I will be used in news system. 123 is id of once news. and i need to change content of selected div in controller. Help me :S
#4

[eluser]egunay[/eluser]
What do you mean by "extended version"?

Anyhoo, create a function in your controller or library that will generate the dynamic content and make an ajax request to that function. otherwise you can't refresh only a div without reloading the page(except iframe, as i said before)
#5

[eluser]marcin346[/eluser]
check it out: view-source:http://bash.org.pl/latest/
When i click on + or -
<span class=" points">3317</span>
<span class="msg">&nbsp;</span>
will be refresh with new data from database.
I want to make this in my website
#6

[eluser]egunay[/eluser]
They are doing it in the exact same way that I told you!

When you click on "+" or "-" links it makes an ajax request (aka xmlhttp) to a certain url with clicked thread id.

That address then takes that id, calls the model and updates the database. When this process finishes that address returns the vote count and ajax request hides the "+" and "-" links and puts the answer returned.

Please look at my first message. There you can find your answer.

Have a look at this: http://api.jquery.com/jQuery.ajax/
this: http://api.jquery.com/click/
and this: http://api.jquery.com/css/

If you don't know javascript or if you are not familiar with ajax, I'd recommend you to learn at least the basics.
#7

[eluser]marcin346[/eluser]
Thanks man. Regards!
#8

[eluser]marcin346[/eluser]
I sill have problems.
I wrote this code:
Code:
<a href="#" type="text/javascript">$.post("http://localhost/fotoszopy/vote", function(data) {
  $("#pasek").html(data);
});[removed]'>+</a>
Its link for 'up'. Controller vote is generating data:
Code:
echo("test test");

When I click on link, div called pasek doesnt change. I tried version without [removed][removed]
Its not works.
I'm need your help




Theme © iAndrew 2016 - Forum software by © MyBB