Visualizzazione dei risultati da 1 a 7 su 7
  1. #1

    [Ajax] encodeURIComponent and urldecode ...........

    Ciao.
    Se spedisco i dati con questo codice:
    Codice PHP:
    var titleValuetrim($('ajax-cat-insert-title').value);
        var 
    data= {catTitle:encodeURIComponent(titleValue)};
        var 
    postVar'cat_title='+encodeURIComponent(json_decode(data));
    xhr.connect('ajax-new-category.php','POST',postVar,insertResponse); 

    con una stringa del genere

    ?èàò%&=string
    se non uso urldecode nel DB
    (category_title varchar(100) utf8_general_ci)
    mi ritrovo una stringa del genere

    %3F%C3%A8%C3%A0%C3%B2%25%26%3Dstring
    mentre se i dati li spedisco con il
    metodo normale la stringa rimane
    invariata.

    Mi potete spiegare perchè ?

    Con encodeURIComponent si deve usare urldecode ?

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

  2. #2
    Codice PHP:
      var postVar'cat_title='+encodeURIComponent(json_encode(data)); 
    naturalmente


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

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

  4. #4
    eh?

    non ho capito il problema, il risultato è quello atteso dato che usi encodeURIComponent 2 volte sul server ti arriva l'encodeURIComponent dell'encodeURIComponent .... tutto regolare

    codice:
    var	unencoded = "è",
    	encoded = encodeURIComponent(unencoded),
    	doublencoded = encodeURIComponent(encoded);
    	
    alert([unencoded, encoded, doublencoded].join("\n"));
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  5. #5
    Originariamente inviato da andr3a
    eh?

    non ho capito il problema, il risultato è quello atteso dato che usi encodeURIComponent 2 volte sul server ti arriva l'encodeURIComponent dell'encodeURIComponent .... tutto regolare

    codice:
    var	unencoded = "è",
    	encoded = encodeURIComponent(unencoded),
    	doublencoded = encodeURIComponent(encoded);
    	
    alert([unencoded, encoded, doublencoded].join("\n"));
    Molte grazie per la risposta

    Scusa ma sono un po duro
    sarà il 100 thread sull'argomento
    che apro su questo benedetto
    json

    Codice PHP:
    // applico encodeURIComponent all'input
    var data= {catTitle:encodeURIComponent(titleValue)}; 
    //qui se passo la stringa json senza encodeURIComponent quando metto
    ad esempio le "" in php ottengo un errore
        
    var postVar'cat_title='+encodeURIComponent(json_decode(data)); 
    da qui l'erroraccio

    questa è la sintassi giusta ?

    Codice PHP:
    var titleValuetrim($('ajax-cat-insert-title').value);
    var 
    data= {catTitle:titleValue};
    var 
    postVar'cat_title='+encodeURIComponent(data.toJSONString()); 

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

  6. #6
    Originariamente inviato da whisher
    questa è la sintassi giusta ?
    direi di si, anche se inviare una key cat_title che contiene un oggetto che ha una key catTitle lo trovo un pò ridondante ... insomma, se usi JSON invii un solo oggetto con tutte le info e come chiave per il server usi, per l'appunto, "JSON="+encodeURIComponent(tutteInfo.toJSONString( )) .... no?
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  7. #7



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

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.