why not working?!

G

Geoff Cox

Hello,

The code below is aimed at passing the date in the yyyyMMdd format
from the javascript calendar in an html file to the php in a another
file which then searches a MySQL database.

For some reason the sendPhp is not working.

I need to send

target=frameright (as the results of the next.php search appear in the
right hand frame), and

submit=1

Any ideas please?!

Cheers

Geoff

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Sounds</title>
<link rel="STYLESHEET" type="text/css"
href="../assets/style/sounds.css">

<script type="text/javascript" src="fcp_calendar.js"></script>
<script type="text/javascript">

window.onload = function() {
cal = new _
fcp.Calendar(document.getElementById("cal_placeholder"));
cal.onselect = function(date) {;

function dateToISO(date) {
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;
return year + month + day;

};

newdate = dateToISO(date);

// the 2 functions below are used to pass the javascript variable
//to the php file, next.php

function xmlreq(){
if(window.XMLHttpRequest){
req = new XMLHttpRequest();
}else if(window.ActiveXObject){
req = new ActiveXObject("Microsoft.XMLHTTP");
}

return(req);

};

function sendPhp(url){
var req = xmlreq();

req.onreadystatechange = stateHandler;
req.open("GET", url, true);
sreq.send(null);
};


sendPhp("next-right.php?searchfield=date&term=newdate&target=frameright'&submit=1");

}

}



</script>
 
W

wisestpotato

For some reason the sendPhp is not working.

What happens when you try to call sendPhp? Do you get a particular
error message.

I have encountered problems in the past when using a relative url with
XMLHttpRequest.open(), so I routinely use fully qualified urls now as
it seems to avoid a lot of problems.

hth.

wp.
 
G

Geoff Cox

What happens when you try to call sendPhp? Do you get a particular
error message.

No error message appears!
I have encountered problems in the past when using a relative url with
XMLHttpRequest.open(), so I routinely use fully qualified urls now as
it seems to avoid a lot of problems.

by full qualified you mean sendPhp("<a href=\"next.php etc?

Cheers

Geoff
 
S

Seth Illgard

Please name the topic with an appropiate title. "Why not working" is
really a bad idea.
Thanks.
 
W

wisestpotato

Above doesn't work though!

Ah, in that case, I'd suggest running a packet analyser such as
Ethereal to examine the network traffic between the client and the
server when xmlhttprequest.open() is executed. See if there is
anything anomalous. I'm assuming here that the web browser is on a
different pc to the server.

Failing that, insert some alert() statements into the sendPHP function
to try and gauge where it is falling over.

You could also try changing the xmlhttprequest to use a synchronous
request and see what is returned:

function sendPhp(url){
var req = xmlreq();

req.onreadystatechange = stateHandler;
req.open("GET", url, false);
req.send(null);

alert(req.status); // show the http status code of the
xmlhttprequest, should be 200
};
 
G

Geoff Cox

Ah, in that case, I'd suggest running a packet analyser such as
Ethereal to examine the network traffic between the client and the
server when xmlhttprequest.open() is executed. See if there is
anything anomalous. I'm assuming here that the web browser is on a
different pc to the server.

Failing that, insert some alert() statements into the sendPHP function
to try and gauge where it is falling over.

You could also try changing the xmlhttprequest to use a synchronous
request and see what is returned:

function sendPhp(url){
var req = xmlreq();

req.onreadystatechange = stateHandler;
req.open("GET", url, false);
req.send(null);

alert(req.status); // show the http status code of the
xmlhttprequest, should be 200
};

It is indeed 200. In fact I am browsing from the same PC at the local
(127.0.0.1) server as I'm still testing this. Is this OK?

The code used to get the 200 is as follows - you can see that I am
trying to get the date, newdate, from the JavaScipt to the php in
another file with the hope that in this file a search will be made of
the MySQL database and the results appear in the right hand frame.
There are 3 frames - a top one and below that a left and right hand
frame. The file with the code below is in the left hand frame.

I not at all sure whether the url is right?

In the php file I am using the $_POST[] array etc.

Any of this seem wrong?!

Cheers

Geoff


<script type="text/javascript" src="fcp_calendar.js"></script>
<script type="text/javascript">

window.onload = function() {
cal = new fcp.Calendar(document.getElementById("cal_placeholder"));
cal.onselect = function(date) {;

//function below changes the date to the //yyyy/MM/dd format

function dateToISO(date) {
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;
//return year + "-" + month + "-" + day;
return year + month + day;
};

newdate = dateToISO(date);

function xmlreq(){
if(window.XMLHttpRequest){
req = new XMLHttpRequest();
}else if(window.ActiveXObject){
req = new ActiveXObject("Microsoft.XMLHTTP");
};

return(req);

};

function stateHandler()
{
var req = xmlreq();
if (req.readyState == 4)
{
if (req.status == 200)
{
success();
};
else
{
failure();
window.alert("failed");
};
};

return true;
};

function sendPhp(url){
var req = xmlreq();
req.onreadystatechange = stateHandler;
req.open("POST", url, false);
req.send(null);
alert(req.status); // show the http status code of the
//xmlhttprequest, should be 200
};

sendPhp("http://127.0.0.1/sounds/members/sounds-right.php?searchfield=\"date\"&term=newdate&submit=1");

};

};



</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top