Visualizzazione dei risultati da 1 a 8 su 8

Discussione: php tramite js

  1. #1
    Utente di HTML.it L'avatar di kakashi
    Registrato dal
    Feb 2005
    Messaggi
    357

    php tramite js

    salve volevo sapere come si puo rikiamare un file php con un copdice js... tipo <script src="http://www.nome sito.com/tag/tagbox.php?userId=..">
    ho provato questo ma nn funziona..
    sapete dirmene altri?

    basta che nel file che punti metti un echo... esempio:

    javascript.php

    code:
    if ( $_GET['tipo'] == "1" )
    {
    echo "function test() { alert ( "questa è la prima prova" ) }" ;
    }
    else if ( $_GET['tipo'] == "2" )
    {
    echo "function test() { alert ( \"Questa è la prova n.2\") } ";
    }



    e poi fai
    <script type="text/javscript" src="javascript.php?tipo=1"></script>

    oppure

    <script type="text/javscript" src="javascript.php?tipo=2"></script>
    io logicamente metto la funziona dentro alert ma da errore

  2. #2
    Utente bannato
    Registrato dal
    Jun 2003
    Messaggi
    3,657

    Re: php tramite js

    Originariamente inviato da kakashi
    salve volevo sapere come si puo rikiamare un file php con un copdice js... tipo <script src="http://www.nome sito.com/tag/tagbox.php?userId=..">
    ho provato questo ma nn funziona..
    sapete dirmene altri?


    io logicamente metto la funziona dentro alert ma da errore
    da errore php o javascript? Cmq si può fare...se cerchi in giro trovarai un post mio che volevo fare questa cosa xo inserendo i banner del sito...

    e poi negli alert metti i punti e virgola all'interno delle funzioni

  3. #3
    Utente di HTML.it L'avatar di kakashi
    Registrato dal
    Feb 2005
    Messaggi
    357
    da errore php
    xke cmq io metto qui alert ( "codece" )

    a me basterebbe sapere come va compilato..
    nel senso se dentro "ci posso mettere l'echo oppure no"
    se ci posso mettere $variabile
    ecc..

  4. #4
    Utente bannato
    Registrato dal
    Jun 2003
    Messaggi
    3,657
    su al codice php puoi far fare qualsiasi cosa, anche fare esplodere il server, ma quello ke conta è l'output ke dai ke in questo caso dev'essere codice javascript.
    Di solito tu fai uscire fuori codice html, ma questo caso è diverso...

    Come fare uscire un codice js? Semplice: fai echo "codice js";

    ma ke errore ti da php?

  5. #5
    Utente bannato
    Registrato dal
    Jun 2003
    Messaggi
    3,657
    ecco cosa ho fatto ip
    Codice PHP:
    <?php
    switch ($_GET['size'])
    {
      case 
    'big'  $img "http://miosito/banners/468x60.jpg"; break;
      case 
    'medium'$img "http://miosito/banners/234x60.gif"; break;
      case 
    'small'$img "http://miosito/banners/120x60.gif"; break;
      case 
    'square'$img "http://miosito/banners/125x125.gif"; break;
      default  : 
    $img "http://miosito/banners/468x60.jpg"; break;
    }
    echo 
    "document.write('<a href=\"http://www.miosito.it\">');";
    echo 
    "document.write('<img src=\"{$img}\" border=\"0\"/>');";
    echo 
    "document.write('</a>');";
    ?>

    e questo codice lo rikiamo così

    codice:
    <script src="http://miosito.it/banner.php" language="javascript"></script>

  6. #6
    Utente di HTML.it L'avatar di kakashi
    Registrato dal
    Feb 2005
    Messaggi
    357
    guarda io ho fatto cosi
    codice:
    <?php
    if ( $_GET['tipo'] == "1" )
    {
    echo "function test() { alert ( "
    ?>
    <script language='JavaScript'>
    <!--
    function winpiccola(theURL,winName,features)
    {
      window.open(theURL,winName,features);
    }
    //-->
    </script>
    
    <form action='wiev.php' method='post' width='160' target='reader' name='form' class='copy' >
    <table border="0" cellpadding="1" cellspacing="0" align="center" width="147" class="copy">
    <tr > 
    <td width="90" valign="top"> 
    <input name="nick"  type="text" size="18" maxlength="100" value="Nick"  onfocus="this.value=''" class="copy">
    </td></tr>
    <tr> 
    <td width="90" valign="top"> 
    <input name="email"  type="text" size="18" maxlength="80" value="email"  onfocus="this.value=''" class="copy">
    </td></tr>
    <tr>
    <td valign="top"><input name="url" type="text" size="18" maxlength="255" value="http://" class="copy"></td>
    </tr>
    <tr> <td>
    <input name="testo" type="text" size="18" maxlength="300" value="Commento" class="copy">
    </td>
    </tr>
    <tr>
    <td height="26"  valign="top"> 
     - <span class="copy">BBcode</span> - <input type="submit" value="GO" title="INVIA" class="copy">
    </td>
    </tr> 
    </table>
    </form>
    
    <?php
    " ) }" ;
    ?>
    erore: Parse error: parse error in D:\Inetpub\webs\amworldit\public\TagBoard\form.php on line 43

  7. #7
    Utente bannato
    Registrato dal
    Jun 2003
    Messaggi
    3,657
    VVoVe:
    [list=1][*]alla fine devi mettere echo ") }";[*]così stampa un output sballato, dovrebbe venire una cosa del genere[/list=1]

    codice:
    function test() { alert ( 
    
    <script language='JavaScript'>
    <!--
    function winpiccola(theURL,winName,features)
    {
      window.open(theURL,winName,features);
    }
    //-->
    </script>
    
    <form action='wiev.php' method='post' width='160' target='reader' name='form' class='copy' >
    <table border="0" cellpadding="1" cellspacing="0" align="center" width="147" class="copy">
    <tr > 
    <td width="90" valign="top"> 
    <input name="nick"  type="text" size="18" maxlength="100" value="Nick"  onfocus="this.value=''" class="copy">
    </td></tr>
    <tr> 
    <td width="90" valign="top"> 
    <input name="email"  type="text" size="18" maxlength="80" value="email"  onfocus="this.value=''" class="copy">
    </td></tr>
    <tr>
    <td valign="top"><input name="url" type="text" size="18" maxlength="255" value="http://" class="copy"></td>
    </tr>
    <tr> <td>
    <input name="testo" type="text" size="18" maxlength="300" value="Commento" class="copy">
    </td>
    </tr>
    <tr>
    <td height="26"  valign="top"> 
     - <span class="copy">BBcode</span> - <input type="submit" value="GO" title="INVIA" class="copy">
    </td>
    </tr> 
    </table>
    </form>
    
     ) }
    nn credo ke sia molto corretto.

  8. #8
    Utente di HTML.it L'avatar di kakashi
    Registrato dal
    Feb 2005
    Messaggi
    357
    codice:
    <?php
    if ( $_GET['tipo'] == "1" )
    {
    echo "function test() { alert ( '";
    ?>
    <script language='JavaScript'>
    <!--
    function winpiccola(theURL,winName,features)
    {
      window.open(theURL,winName,features);
    }
    //-->
    </script>
    
    <form action='wiev.php' method='post' width='160' target='reader' name='form' class='copy' >
    <table border="0" cellpadding="1" cellspacing="0" align="center" width="147" class="copy">
    <tr > 
    <td width="90" valign="top"> 
    <input name="nick"  type="text" size="18" maxlength="100" value="Nick"  onfocus="this.value=''" class="copy">
    </td></tr>
    <tr> 
    <td width="90" valign="top"> 
    <input name="email"  type="text" size="18" maxlength="80" value="email"  onfocus="this.value=''" class="copy">
    </td></tr>
    <tr>
    <td valign="top"><input name="url" type="text" size="18" maxlength="255" value="http://" class="copy"></td>
    </tr>
    <tr> <td>
    <input name="testo" type="text" size="18" maxlength="300" value="Commento" class="copy">
    </td>
    </tr>
    <tr>
    <td height="26"  valign="top"> 
     - <span class="copy">BBcode</span> - <input type="submit" value="GO" title="INVIA" class="copy">
    </td>
    </tr> 
    </table>
    </form>
    <?php
    echo" ' ) }";
    }
    ?>
    facendo come indicato sopra mi stampa anche
    function test() { alert (

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.