how can i replace ajax id with a variable?

Discussion in 'PHP' started by macaela, Sep 3, 2011.

  1. #1
    how can i replace ajax id with a variable?

    Postby jonathan » Sat Sep 03, 2011 4:14 pm
    Hi can i put the ajax div into a variable
    or instead of using get element by id can i use get element by $film
    the reason i want to do that is that have the 3 files the ajax function, the query file, and the display page
    now the display page display the ajax function using the (document.getElementById('ajaxFilmLink') so on the display page i have a div=ajaxFilmLink. this returns the value fine but my problem now is that instead of a div=ajaxFilmLink i want a variable that works just like the div=ajaxFilmLink
    because i need to store those values on jwplayer which usualy would be like this
     'file': '<?php echo $efilm; ?>',
    PHP:
    i tried
     'file': '<?php echo div=ajaxFilmLink ; ?>',
    PHP:
    but that doesnt work is there a way i can grab that ajax div value and store on a variable $efilm so that i can echo anywhere i want?
    my files 3 files are the follwings
    ajax file
    var ajaxRequest10;
                    // The variable that makes Ajax possible!              
            try
            {// Opera 8.0+, Firefox, Safari        
               ajaxRequest10 = new XMLHttpRequest();
            }
               catch (e)
            {// Internet Explorer Browsers         
                    try
            {
                    ajaxRequest10 = new ActiveXObject("Msxml2.XMLHTTP");
            }
               catch (e)
            {
                    try
            {
                    ajaxRequest10 = new ActiveXObject("Microsoft.XMLHTTP");
            }
               catch (e)
            {// Something went wrong                               
               alert("Your browser broke!");
            return false;
      }    
     }
    }      
                    // ********** DATA 10 ********** FILM LINK     
                    // Create a function that will receive data sent from the server       
    ajaxRequest10.onreadystatechange = function()
            {
                    if(ajaxRequest10.readyState == 4)
                     {     
                            var ajaxDisplay10 = document.getElementById('ajaxFilmLink');
                            ajaxDisplay10.innerHTML = ajaxRequest10.responseText;
                    }
            }      
                    // var fid = document.getElementById('fid').value;     
    var queryString10 = "?fid=" + fid;      ajaxRequest10.open("GET", "../jrp/setfilmlink.php" + queryString10, true);      ajaxRequest10.send(null);
    PHP:
    queryfile named (setfilmlink.php)
    <?php
    include("../../includes/config.php");
    mysql_connect($db_address, $db_username, $db_password);mysql_select_db($db_name) or die(mysql_error());
    $fid = $_GET['fid'];   
    $fid = mysql_real_escape_string($fid);
    $query10 = "SELECT * FROM films WHERE (film_id = '$fid')";     
    $qry_result10 = mysql_query($query10) or die(mysql_error());
    while($row10 = mysql_fetch_array($qry_result10))       
    {       $urlfid="http://www.onfilm.biz/streaming/home/".$row10['client']."/".$row10['client_office']."/".$row10['filename'].".mp4";?>          
    <a class="hofwhite14" href="#" onclick="loadNplay('<?php echo $urlfid; ?>')"><u></u>Property Film</u></a>
    <?php   }mysql_close();
     //EDIT 290510
    ?>
    PHP:
    and the display page is named (indextest.php)
    
    <div id="ajaxFilmLink">
     </div>
    PHP:
    the main reason i want to change is because when i simple try to put the query page on the indextest.php page the query doesnt retrieve the data from the database
    so can i put the ajax div into a variable
    or instead of using get element by id can i use get element by $film
     
    macaela, Sep 3, 2011 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    "Ajax div"? A div is an HTML element. AJAX is a method used to communicate between the client (in Javascript) and the server (in PHP, Cold Fusion, ASP, etc.) What is the data you're retrieving and sending to the client, the name of the movie or the movie data itself (video content)? AJAX is the wrong way to retrieve a file full of data - you use the file functions, starting with fopen(), for that.

    There's no "getElementBy$variable" in Javascript, you can get an element by name, tagname or id. The best you can do is echo "getElementById('$film')" in PHP. (Or by name or tagname.) But be aware - this happens on the server, not in the client, so it has to be valid before the page is sent to the client. If you want it coming via a request from the client, you can echo the data, but you have to put it into the DOM flow with Javascript.
     
    Rukbat, Sep 3, 2011 IP