Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2001
    Messaggi
    170

    Concatena invece di stampare

    Ho questa variabile
    Codice PHP:
    var param 'message=' document.getElementById('txt_message').value
    che mi prende il testo da un form, se nell'input vado a scrivere "+ ciao" la variabile invia al database "ciao" senza il +. Credo che legga il + come segno di concatenamento e non come stringa di testo, come posso ovviare a questo?

    qui il pezzo di codice intero
    Codice PHP:
      if (sendReq.readyState == || sendReq.readyState == 0) {
                        
    sendReq.open("POST"'getChat.php?main=1&last=' lastMessagetrue);
                        
    sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                        
    sendReq.onreadystatechange handleSendChat
                        var 
    param 'message=' document.getElementById('txt_message').value;
                        
    sendReq.send(param);
                        
    document.getElementById('txt_message').value '';
                    } 

  2. #2
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  3. #3
    Utente di HTML.it
    Registrato dal
    Feb 2001
    Messaggi
    170
    grazieeeeeeeeeee

    Metto cosa ho fatto tanto per far capire eventualmente qualcosa a chi cercasse in futuro
    Codice PHP:

                    
    if (sendReq.readyState == || sendReq.readyState == 0) {
                        
    sendReq.open("POST"'getChat.php?main=1&last=' lastMessagetrue);
                        
    sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                        
    sendReq.onreadystatechange handleSendChat
                        var 
    param 'message=' encodeURIComponent(document.getElementById('txt_message').value);
                   
                        
    sendReq.send(param);
                        
    encodeURIComponent(document.getElementById('txt_message').value);                }                           
                } 

  4. #4
    Originariamente inviato da Mary Angy
    grazie, ma l'ho messo così (è giusto?)e non viene lo stesso
    Codice PHP:
                function sendChatText() {
                    if (
    document.getElementById(encodeURIComponent('txt_message')).value == '') {
                        
    alert("Non hai scritto niente");
                        return;
                    }
                    if (
    sendReq.readyState == || sendReq.readyState == 0) {
                        
    sendReq.open("POST"'getChat.php?main=1&last=' lastMessagetrue);
                        
    sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                        
    sendReq.onreadystatechange handleSendChat
                        var 
    param 'message=' document.getElementById(encodeURIComponent('txt_message')).value;
                        
    param += '&chat=1';
                        
    sendReq.send(param);
                        
    document.getElementById(encodeURIComponent('txt_message')).value '';
                    }                           
                } 
    Bisogna dire che sei creativo
    non avevo mai visto utilizzare
    encodeURIComponent in questo modo VVoVe:


    se provi così forse è meglio
    Codice PHP:
    encodeURIComponent(document.getElementById('txt_message').value



    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  5. #5
    Utente di HTML.it
    Registrato dal
    Feb 2001
    Messaggi
    170
    Ecco appunto stavo modificando il post

    Grazie

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.