#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    28
    Rep Power
    0

    Running an audiot file


    Having problem starting an mp3 file from javascript/ajax. Current logic is that ajax calls an php file that has html code inside that executes the mp3 launch, but that doesn't seem to work that well, or at all for that matter.

    index
    Code:
    	xmlhttp9=new XMLHttpRequest();
    	xmlhttp9.onreadystatechange=function(){
    		if (xmlhttp9.readyState==4 && xmlhttp9.status==200)  { } }
    	alert("start");
    	xmlhttp9.open("GET","alarm.php",true);
    	xmlhttp9.send();
    alarm.php (works by itself, plays alarm on open)
    PHP Code:
    <?php?><object height="0" width="0" data="audio/alarm.mp3"></object><?php?>
    any ideas?
  2. #2
  3. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4124
    how are you embedding the retuned html code into the 'parent' (calling) page?

    Given the code you have supplied, the XHR object has retrieved text from the server, but you have yet to do anything with this (eg inject it into the dom and have it parsed as html).

    Remember, The XHR is not a substitute for a browser...but is an optional data communication link between the browser/the page being browsed (by means of the browser executing your javascript) and your server
    Last edited by Northie; September 30th, 2013 at 08:32 AM.
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    28
    Rep Power
    0
    Those are so fancy words , care to elaborate ?
  6. #4
  7. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4124
    Humm, not sure which of my words are fancy....lets look at things like this:

    If that is the entirety of your script(s) then all you're doing is fetching data from your server (the raw HTML returned). You are not doing anything with it.

    It will only do what you expect when treated as HTML in the context of your browser (as demonstrated when you access the file directly).

    So to make it do what you want you need to update the DOM with the fetched HTML.

    Make more sense now?
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    28
    Rep Power
    0
    Code:
    document.getElementById("sound_element").innerHTML= "<embed src='audio/alarm.mp3' hidden=true autostart=true loop=false>";
    solved

    Comments on this post

    • Northie agrees : Yep - that's 'doing something' with the returned data :)

IMN logo majestic logo threadwatch logo seochat tools logo