How to use $_post with js??

Discussion in 'JavaScript' started by 123GoToAndPlay, May 11, 2007.

  1. #1
    At the moment i am using this js function
    
    function saveData() {
    	//store title and descr
    	dataTitle = 'routeTitle=' + document.getElementById("dataTitle").value;
    	dataDescr = document.getElementById("dataDescr").value;
    userID = 'userID='+ document.getElementById("userID").value;
    	window.location.href = "save-data.php?dataTitle+"&"+userID+"&dataDescr="+dataDescr;
    }
    
    Code (markup):
    but i would like to use $_post in save-data.php. How should i rewrite function saveData()?

    regards
     
    123GoToAndPlay, May 11, 2007 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    ajsa52, May 11, 2007 IP
  3. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #3
    you need to encode that string as a url with something like

    var thePost = 'key=' + encodeURI( 'value' ) + '&whatever=' + encodeURI( 'wherever' ) ;

    however, I would use ajax to post the form and serialize() [ prototype ] to make the string instead of messing about, get prototype and look through the api docs on the site......

    otherwise change $_POST to $_GET or $_REQUEST to have the script use post or get data
     
    krakjoe, May 11, 2007 IP
  4. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hmm, ok

    I am asking how to do $_POST in a javascript function.

    The $_GET/$_REQUEST way seems to work in firefox. I thought $_GET was restricted to 250 chars???/
     
    123GoToAndPlay, May 12, 2007 IP