php variable passed by jquery and get it for $ _GET to another php page

Discussion in 'PHP' started by chiqui3d, Sep 18, 2010.

  1. #1
    I usually go to the news of the story expanded, passes the variable with a while, as follows:
    
    while ($noticias = @mysql_fetch_array($sql)) {
    $sqll = mysql_query("SELECT * FROM categorias WHERE id='".$noticias['categoria']."'");
    $datos = mysql_fetch_array($sqll);
    <div class="leermas">[COLOR="red"]<a href="noticias.php?n='.$noticias['id'].'">[/COLOR]<strong>(Leer m&aacute;s)</strong></a></div>
    </div></div>';
    
    }
    
    PHP:
    but now I want is to load the content of the page in a div and I usually when I don't have to pass php variable in this way:
    the link for load content
    <a  class="recursostopwebjqampliada" href="">  
    PHP:
    jQuery code that I have it in an external file called load.js
    
    $(document).ready(function() {  
        $(".recursostopwebjqampliada").live("click", function(){ 
                                       
    $("div#main2").load("topwebjq_ampliada.php?n='.$noticias['id'].'");//AQUI DONDE ESTA LA VARIABLE
         });  
     });
    
    PHP:
    and the page that loads the div I get the variable as follows:
    
    $id = $_GET['n'];  
    
    PHP:
    the problem is that jQuery does not read the file php load.js
    then how I can fix it
    
    
    load("topwebjq_ampliada.php?n='.$noticias['id'].'"
    
    PHP:

     
    chiqui3d, Sep 18, 2010 IP
  2. axelay

    axelay Peon

    Messages:
    54
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You are trying to pass a PHP variable to a JS file, it is not surprising it is not working.

    If you put the jQuery call inside your PHP file it could work.

    $(document).ready(function() {  
        $(".recursostopwebjqampliada").live("click", function(){ 
                                       
    $("div#main2").load("topwebjq_ampliada.php?n=<?php echo $noticias['id'];?>");//AQUI DONDE ESTA LA VARIABLE
         });  
     });
    Code (markup):
    Other solution would be to pass a variable to your JS function but it is hard to tell without checking the full code

    aXe
     
    axelay, Sep 21, 2010 IP
  3. ashishkg

    ashishkg Active Member

    Messages:
    233
    Likes Received:
    8
    Best Answers:
    3
    Trophy Points:
    68
    #3
    Yes, its a good solution.
     
    ashishkg, Sep 21, 2010 IP