How do I run a server side script?

C

Corvet

I tried run PHP server-side script by setting an image URL, php script
should parse remote page and return result.
I tried two versions, but none of them work.

<script type="text/javascript">
var dummyimage = new Image();
dummyimage.src = "http://www.site.com/script.php?param="
</script>

<script type="text/javascript">
var myScript = "http://www.site.com/script.php";
var milliSecSinceUE = (new Date()).getTime();
var dummyimage = new Image();
dummyimage.src = dummyimage+"?nocache="+milliSecSinceUE;
</script>

Error log show info "File not found": File not found
[/hsphere/local/home/site/site.com/dis/rep/[objectHTMLImageElement]]

Regards,
 
L

Luuk

I tried run PHP server-side script by setting an image URL, php script
should parse remote page and return result.
I tried two versions, but none of them work.

<script type="text/javascript">
var dummyimage = new Image();
dummyimage.src = "http://www.site.com/script.php?param="
</script>

<script type="text/javascript">
var myScript = "http://www.site.com/script.php";
var milliSecSinceUE = (new Date()).getTime();
var dummyimage = new Image();
dummyimage.src = dummyimage+"?nocache="+milliSecSinceUE;
</script>

Error log show info "File not found": File not found
[/hsphere/local/home/site/site.com/dis/rep/[objectHTMLImageElement]]

Regards,

<script type="text/javascript">
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", "http://www.site.com/script.php?param=", false );
xmlHttp.send( null );
response = xmlHttp.responseText;
alert(response);
</script>
 
T

Thomas 'PointedEars' Lahn

Corvet said:
I tried run PHP server-side script by setting an image URL, php script
should parse remote page and return result.

In order to do so, you have to tell the PHP script where to find the
"remote page" somehow.
I tried two versions, but none of them work.

<script type="text/javascript">
var dummyimage = new Image();
dummyimage.src = "http://www.site.com/script.php?param="
</script>

So, where do you tell the PHP script what the "remote page" is?
<script type="text/javascript">
var myScript = "http://www.site.com/script.php";
var milliSecSinceUE = (new Date()).getTime();
var dummyimage = new Image();
dummyimage.src = dummyimage+"?nocache="+milliSecSinceUE;
</script>

Error log show info "File not found": File not found
[/hsphere/local/home/site/site.com/dis/rep/[objectHTMLImageElement]]

As you can observe, the string representation of an Image instance is not
some randomly fitting URI. And since the representation does not start with
a `/', it is considered a relative URI of a resource that does not exist, of
course.

You are obviously confused; calm down, think it through, and try again.
Then again, this appears to have hardly anything to do with the topic of
this newsgroup.

<http://jibbering.com/faq/#posting>


PointedEars
 
C

Corvet

Luuk said:
I tried run PHP server-side script by setting an image URL, php script
should parse remote page and return result.
I tried two versions, but none of them work.

<script type="text/javascript">
var dummyimage = new Image();
dummyimage.src = "http://www.site.com/script.php?param="
</script>

<script type="text/javascript">
var myScript = "http://www.site.com/script.php";
var milliSecSinceUE = (new Date()).getTime();
var dummyimage = new Image();
dummyimage.src = dummyimage+"?nocache="+milliSecSinceUE;
</script>

Error log show info "File not found": File not found
[/hsphere/local/home/site/site.com/dis/rep/[objectHTMLImageElement]]

Regards,

<script type="text/javascript">
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", "http://www.site.com/script.php?param=", false );
xmlHttp.send( null );
response = xmlHttp.responseText;
alert(response);
</script>
-----------

Thank you. This works, but just not in the way I meant, php script parse
html page and should show result by echoing html code inside body.
echo $html;


Regards,
Corvet
 
C

Corvet

In order to do so, you have to tell the PHP script where to find the
"remote page" somehow.


The URL of target page to parse specified inside PHP code.

So, where do you tell the PHP script what the "remote page" is?
<script type="text/javascript">
var myScript = "http://www.site.com/script.php";
var milliSecSinceUE = (new Date()).getTime();
var dummyimage = new Image();
dummyimage.src = dummyimage+"?nocache="+milliSecSinceUE;
</script>
Error log show info "File not found": File not found
[/hsphere/local/home/site/site.com/dis/rep/[objectHTMLImageElement]]
As you can observe, the string representation of an Image instance is not
some randomly fitting URI. And since the representation does not start with
a `/', it is considered a relative URI of a resource that does not exist, of

You are obviously confused; calm down, think it through, and try again.
Then again, this appears to have hardly anything to do with the topic of
this newsgroup.

well, I tried javascript above with relative address:

var myScript = "/script.php";

but it not work also.

Regards,
Corvet
 
T

Thomas 'PointedEars' Lahn

Corvet said:
The URL of target page to parse specified inside PHP code.

Exactly. How you can do this is beyond the scope of this newsgroup, as URIs
are not JS/ES-specific, neither is PHP. IOW, first you need to try solving
this problem *without* client-side scripting.

You did not answer my question (but quoted it regardless), which is telling
me that you have not thought this through as I suggested, which does not
bode well for your being able to solve this little problem at this point in
the learning curve.
<script type="text/javascript">
var myScript = "http://www.site.com/script.php";
var milliSecSinceUE = (new Date()).getTime();
var dummyimage = new Image();
dummyimage.src = dummyimage+"?nocache="+milliSecSinceUE;
</script>
Error log show info "File not found": File not found
[/hsphere/local/home/site/site.com/dis/rep/[objectHTMLImageElement]]

As you can observe, the string representation of an Image instance is not
some randomly fitting URI. And since the representation does not start
with a `/', it is considered a relative URI of a resource that does not
exist, of course.

You are obviously confused; calm down, think it through, and try again.
Then again, this appears to have hardly anything to do with the topic of
this newsgroup.

well, I tried javascript above with relative address:

There is no "javascript".
var myScript = "/script.php";

but it not work also.

Did you notice that you are not using the `myScript' variable anywhere?

You are still confused.


PointedEars
 
V

VK

php script parse
html page and should show result by echoing html code inside body.
echo $html;

Then what does it have to do with Image? Image is one of supported
graphics formats (say GIF or JPEG), served from your PHP script with a
proper Content-type (say image/gif) and followed by a proper data
block. If your server on image request sends non-image Content-type
and/or non-proper image data then the browser reaction depends on its
build-in virus protection. In the simplest case the whole request
result for "image" will be ignored.

So if you simply need to trig your PHP for some server-side activity,
then you may keep using say 1x1 transparent GIF. Just don't forget
that besides all other things your PHP must respond with image/gif
properly formatted image stream.

If you need a textual response from PHP to handle it client-side then
it has nothing to do with images. Luuk gave you a working example of
how it could be done.
 
C

Corvet

VK said:
php script parse
html page and should show result by echoing html code inside body.
echo $html;


If you need a textual response from PHP to handle it client-side then
it has nothing to do with images. Luuk gave you a working example of
how it could be done.
---------

Luuk's script works, but how to write response into body, not into popup
window?


Corvet
 
T

Thomas 'PointedEars' Lahn

Corvet said:
Luuk's script works, but how to write response into body, not into popup
window?

The simplest way is assigning a string value to the `innerHTML' property of
an element with a non-EMPTY content model. We have discussed the options
recently (again). Please search before you post.


PointedEars
 
C

Corvet

The simplest way is assigning a string value to the `innerHTML' property of
an element with a non-EMPTY content model. We have discussed the options
recently (again). Please search before you post.


like this?

<script type="text/javascript">
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", "http://www.site.com/script.php", false );
xmlHttp.send( null );
response = xmlHttp.responseText;
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
</script>

<div id="myDiv"></div>

didn't return anything.


Corvet
 
C

Corvet

You did not answer my question (but quoted it regardless), which is telling
me that you have not thought this through as I suggested, which does not
bode well for your being able to solve this little problem at this point in
the learning curve.
Did you notice that you are not using the `myScript' variable anywhere?


yes I see now. I tried this, but not work, again:

<script type="text/javascript">
var myScript = "http://www.site.com/script.php";
var milliSecSinceUE = (new Date()).getTime();
var dummyimage = new Image();
dummyimage.src = myScript+"?nocache="+milliSecSinceUE;
</script>



Corvet
 
T

Thomas 'PointedEars' Lahn

Corvet said:
like this?

<script type="text/javascript">
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", "http://www.site.com/script.php", false );

It is a bad idea to use synchronous request-response handling (`false')
there, as that blocks the browser's UI thread until the response has been
received. It should be `true', and the `onreadystatechange' property should
be assigned to, instead.
xmlHttp.send( null );
response = xmlHttp.responseText;
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
</script>

<div id="myDiv"></div>

didn't return anything.

Wrong. It "returns" a TypeError because the `div' element has not yet been
parsed, and therefore has no representation in the document tree, when you
try to access the corresponding object. So document.getElementById("myDiv")
returns `null', and `null' has no properties. You need to reverse the order
of the element, or better yet put the script code in a function that you
call later, after the document has been fully loaded.

Besides, you have not declared your identifiers variables with the `var'
keyword, which is error-prone.

These are very basic issues, and ISTM you are not quite ready for this yet.
Have you read the FAQ as I recommended?


PointedEars
 
T

Thomas 'PointedEars' Lahn

Corvet said:
yes I see now. I tried this, but not work, again:

"Does not work" is not an error description.
<script type="text/javascript">
var myScript = "http://www.site.com/script.php";
var milliSecSinceUE = (new Date()).getTime();
var dummyimage = new Image();
dummyimage.src = myScript+"?nocache="+milliSecSinceUE;

This can only work if the computed URI refers to an image resource, assuming
that you want to load an image and not do something else. The
+"?nocache="+milliSecSinceUE part should be unnecessary then, as long as you
send the correct cache-controlling response headers instead.

Please find a better news client, one that does not break quotes, for
example (see above, not fixed this time).


PointedEars
 
L

Luuk

It is a bad idea to use synchronous request-response handling (`false')
there, as that blocks the browser's UI thread until the response has been
received. It should be `true', and the `onreadystatechange' property should
be assigned to, instead.


Wrong. It "returns" a TypeError because the `div' element has not yet been
parsed, and therefore has no representation in the document tree, when you
try to access the corresponding object. So document.getElementById("myDiv")
returns `null', and `null' has no properties. You need to reverse the order
of the element, or better yet put the script code in a function that you
call later, after the document has been fully loaded.

Besides, you have not declared your identifiers variables with the `var'
keyword, which is error-prone.

These are very basic issues, and ISTM you are not quite ready for this yet.
Have you read the FAQ as I recommended?


PointedEars


<html>
<head>
<title>TITLE</title>
<script type="text/javascript">
function doit() {
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", "http://www.site.com/script.php", false );
xmlHttp.send( null );
response = xmlHttp.responseText;
document.getElementById("myDiv").innerHTML = response;
}
</script>
</head>
<body onload="doit();">
<div id="myDiv"></div>
.......

Only after the page is loaded completely, the "doit()" function is
executed...
 
C

Corvet

Luuk said:
<html>
<head>
<title>TITLE</title>
<script type="text/javascript">
function doit() {
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", "http://www.site.com/script.php", false );
xmlHttp.send( null );
response = xmlHttp.responseText;
document.getElementById("myDiv").innerHTML = response;
}
</script>
</head>
<body onload="doit();">
<div id="myDiv"></div>
......

Only after the page is loaded completely, the "doit()" function is
executed...
-----------

well, I can't use 'body onload' method, as my pages is dynamically generated
by CMS and I can't add call to body tag.
Is there a work around?

Corvet
 
C

Captain Paralytic

-----------

well, I can't use 'body onload' method, as my pages is dynamically generated
by CMS and I can't add call to body tag.
Is there a work around?

Corvet

Yes there are lots. You keep telling us that you can't do things that
we know full well that you can do - if only you knew what you were
doing (you were doing the same over in comp.lang.php).

What you are really after is for someone to do all your work for you.

It's not often that I agree with T(P)L, but in this case he is 100%
correct. You are not ready for this yet.

Pretty much all CMSs allow you to add scripts and events. If you had
the first idea what you were doing you would know how to add an event
using a script.
 
T

Thomas 'PointedEars' Lahn

Corvet said:
well, I can't use 'body onload' method, as my pages is dynamically
generated by CMS and I can't add call to body tag.
Is there a work around?

Yes.


PointedEars
 
C

Corvet

Thomas 'PointedEars' Lahn said:
Yes.


PointedEars
--

Why not show it off? (especially if you're consider yourself an expert in
javascript?)
I know there is also
window.onload = init;
method, but I'm not will it suitable in my case.
 

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

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,737
Latest member
Georgeengab

Latest Threads

Top