Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-23-2007, 11:59 PM   PM User | #1
StupidRalph
Senior Coder

 
Join Date: Mar 2003
Location: Atlanta
Posts: 1,037
Thanks: 14
Thanked 30 Times in 28 Posts
StupidRalph is on a distinguished road
AJAX and Actionscript

I have a page (genre.php) that has different songs and on this page you can rate each song. I also have a flash mp3 player that pops up in a different window so you can hear each song. Members want the ability to rate songs from the mp3 player. I've already added this functionality to update the DB courtesy of actionscript. The problem I am running into is how can update the main page (genre.php) with the new rating from the mp3 player? I think the problem I am running into is setting the correct image to be updated.

I was going to do this all in flash but I'm using SWFObject to embed the .swf files and its really slow for the page to load since its loading 50 songs per page.

I was thinking of doing something like this...
Code:
//var xmlHttp = create XMLHTTPRequest according to browser
...
xmlHttp.onreadystatechange=function()
  {
  if(xmlHttp.readyState==4)
	{
	document.imgRate.src = xmlHttp.responseText; //how do I target the correct image to change the src??? How should I set 'imgRate' on the left side of the = sign?
	}
  }
xmlHttp.open("POST","updateRate.php",true);
xmlHttp.send(null);
}
When a person clicks the song name I use javascript to launch the mp3 player. Do I use that as an opportunity to pass the imgRate id of the specific song or something?

I've never used AJAX and very minimal javascript experience but I can understand the basics so feel free to use any jargon necessary.

Quote:
Originally Posted by A1ien51
Are you reusing the Object?

The correct order with IE is

open()
onreadystatechange
send()

If you have onreadystatechange before the open, IE will not work.

Eric
I've seen this in another post here...considering the fact that I learned this from w3schools am I coding this wrong as well? (Reference to aforementioned post)

Edit: I didn't want to just post a bunch of unnecessary code. Please tell me if you need to see other code in order to assist me on this situation.

Edit: How do I change the Thread Title as its confusing seeing that I'm not necessarily needing actionscript and AJAX to communicate. Although, if you know of a way to do that, that will be helpful too
__________________
Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

Last edited by StupidRalph; 07-24-2007 at 12:23 AM..
StupidRalph is offline   Reply With Quote
Old 07-27-2007, 06:42 AM   PM User | #2
StupidRalph
Senior Coder

 
Join Date: Mar 2003
Location: Atlanta
Posts: 1,037
Thanks: 14
Thanked 30 Times in 28 Posts
StupidRalph is on a distinguished road
Sometimes...I feel like I'm on my own...j/k. I fixed it. Apparently was overthinking this and wanted to query the DB to find out the rating once it posted. When thats simply not necessary since I can call javascript directly from actionscript. So really all that needed to be done is write a function on the parent page (genre.php) and pass the parameters via actionscript.

genre.php
Code:
//code that opens the child window container my mp3 player
function launchPlayer(id,title){
	genre=<?=$genre;?>  //variable set via PHP
	player= window.open ('player2.php?id='+id+'&genre='+genre, title,'location=0,status=0,scrollbars=0,menubar=no,resizable=no,width=480,height=250');
}


//this is the function I added to the parent page.
function updateRate(id,rating){
	//each rate image id is named 'rate' + its primary key from the database. (for example: <img id="rate1111" src="images/headphones.gif" />)
	window.document.getElementById(id).src = 'images/headphones'+ rating +'.gif';
}
player.php
Code:
//this is how I call that function from my actionscript
getURL("javascript: window.opener.updateRate('rate"+ songID + "','" + this.rate_value + "');");
And there you have it. Sometimes you just need to back away from your problems and revisit with a clear mind .
__________________
Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.
StupidRalph is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:53 PM.


Advertisement
Log in to turn off these ads.