Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 4 votes, 4.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-13-2010, 01:29 AM   PM User | #1
Jazzo
Regular Coder

 
Jazzo's Avatar
 
Join Date: Apr 2008
Location: New York City
Posts: 164
Thanks: 20
Thanked 2 Times in 2 Posts
Jazzo is an unknown quantity at this point
Assign Javascript Variable to PHP

I have a javascript variable that I need to pass to a php variable. Since PHP is server-side, I figured the only way to send the js variable is to refresh. However, I don't want to reload the page. How can I send a javascript variable to php on the same page without reloading? For example, I want to assign the js variable "com" to the PHP variable "$com".

Thanks,
Jazzo

P.S. So far, I've defined my Ajax request as such:
Code:
req = (function () {
  if (window.XMLHttpRequest) {
    return new XMLHttpRequest();
  }
  else if (window.ActiveXObject) {
    return new ActiveXObject("Microsoft.XMLHTTP");
  }
  else {
    return null;
  }
}());
__________________
~Julian
14 y/o web developer, drummer, and Bridge player

Last edited by Jazzo; 03-13-2010 at 01:33 AM..
Jazzo is offline   Reply With Quote
Old 03-17-2010, 09:51 PM   PM User | #2
tfit
New Coder

 
Join Date: May 2008
Posts: 80
Thanks: 3
Thanked 3 Times in 3 Posts
tfit is an unknown quantity at this point
Your code is not enough to request anything from the server let alone doing something useful when you get a response. How are you passing/handling the variables. I guess you're going to use a form. You can pass values to the server either with get/post and php will receive it in $_GET/$_Post variable. Try to get a xmlhttprequest structure which you can make your own. Everytime I see how others make them and I go or . If you get that, much is already done. And afterwards you need some understanding of DOM.
tfit is offline   Reply With Quote
Old 10-30-2010, 09:46 PM   PM User | #3
alacka
New to the CF scene

 
Join Date: Oct 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
alacka is an unknown quantity at this point
On one site has found a good script can help you: Passing Javascript variable to php
alacka is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:59 PM.


Advertisement
Log in to turn off these ads.