How to send javascript variable to php file?

Discussion in 'JavaScript' started by abpwebservices, Oct 10, 2011.

  1. #1
    Hello to everybody!

    I have a small issue.

    I have this piece of code (just a small part from a html file):

    $.prompt(temp,{
    					callback: function(v,m,f){
    						var str = "text";
    						var trimit ="";
    						$.each(f,function(i,obj){
    							trimit += i + " - <em>" + obj + "</em><br />";
    						});	
    						//$.prompt(trimit);
    						$.prompt(str);
    					}
    				});
    Code (markup):
    How can I send variable "trimit" as a message to an e-mail adress without changing the page (as a hidden process - i mean without loading a visible page)?
    I was thinking to use mail() in a php file. How can I send the variable to a php file without changing the page (hidden process)?

    Can somebody help me with a code?

    Thanks in advance,
    Adrian
     
    abpwebservices, Oct 10, 2011 IP
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    You pass it using post or get methods, jquery has built-in ajax to achieve this.

    In your PHP file, you catch those variables with $_GET or $_POST or $_REQUEST
     
    Rainulf, Oct 11, 2011 IP
  3. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #3

    the easiest method is to pass through GET method by redirecting you page,

    window.location = "http://www.domain.com/page.php?trimit="+trimit;

    if you don't like to redirect,you can use AJAX
     
    JohnnySchultz, Oct 13, 2011 IP