freedomgw
02-01-2011, 02:10 PM
Hi, I wish to resurrect this topic because I am encountering some problem even after looking through your examples . I hope someone out there can help me with my coding in AJAX. I am trying to send two javascript variables to PHP variables using AJAX. Please have a look at my code, thank you in advance!
In my javascript, I am using YUI dual slider, so when I end sliding the mouse I want to engage these functions such that....
javascript code
var psavestate = function(){ // THESE ARE CURRENTLY SAVED VALUES, WE CAN NOW USE THESE VALUES FOR A PHP FUNCTION FOR QUERYING
var url = "/Applications/MAMP/htdocs/trunk/application/modules/cne/admin/view/scripts/index/index.phtml",
savemin = pconvert(pslider.minVal), // pconvert is some function
savemax = pconvert(pslider.maxVal),
requestMinData = "savemin=" + savemin,
requestMaxData = "savemax=" + savemax;
var request = createRequest();
if (request == null) {
alert("Unable to create request, please update your browser to use this feature.");
return;
}
request.onreadystatechange = checkRequest();
request.open("POST", url, true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send(requestMinData);
request.send(requestMaxData);
}
pslider.subscribe('slideEnd', psavestate); // Slider ends, start method psavestate
})
// Browser Support Code
function createRequest(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
return ajaxRequest;
}
function checkRequest() {
if (request.readyState == 4) {
if (request.status == 200) {
var response = request.responseText;
//alert(response);
}
}
}
As for my php code, I wrote the following to test to see if this worked... and so far it hasn't been working quite well for me....
<?php $v = $_REQUEST['savemin'];
echo $v; ?>
Please take a look, thank you in advance again!
In my javascript, I am using YUI dual slider, so when I end sliding the mouse I want to engage these functions such that....
javascript code
var psavestate = function(){ // THESE ARE CURRENTLY SAVED VALUES, WE CAN NOW USE THESE VALUES FOR A PHP FUNCTION FOR QUERYING
var url = "/Applications/MAMP/htdocs/trunk/application/modules/cne/admin/view/scripts/index/index.phtml",
savemin = pconvert(pslider.minVal), // pconvert is some function
savemax = pconvert(pslider.maxVal),
requestMinData = "savemin=" + savemin,
requestMaxData = "savemax=" + savemax;
var request = createRequest();
if (request == null) {
alert("Unable to create request, please update your browser to use this feature.");
return;
}
request.onreadystatechange = checkRequest();
request.open("POST", url, true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send(requestMinData);
request.send(requestMaxData);
}
pslider.subscribe('slideEnd', psavestate); // Slider ends, start method psavestate
})
// Browser Support Code
function createRequest(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
return ajaxRequest;
}
function checkRequest() {
if (request.readyState == 4) {
if (request.status == 200) {
var response = request.responseText;
//alert(response);
}
}
}
As for my php code, I wrote the following to test to see if this worked... and so far it hasn't been working quite well for me....
<?php $v = $_REQUEST['savemin'];
echo $v; ?>
Please take a look, thank you in advance again!