We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › processing  >> javascript >> php
Page Index Toggle Pages: 1
processing  >> javascript >> php (Read 2832 times)
processing  >> javascript >> php
May 31st, 2005, 11:44am
 
Hi,

I wrote a little sketch which should save data in a textfile on the server.

I use the netscape.javascript library to write a value from the applet to a hidden form. This form is then sent to a php-skript.

To my great happiness this works, but (and here my mood drops) only in internet-explorer. not in opera and not in firefox. there seems to be something wrong with my javascript, I guess.

Maybe you can give me a hint?

heres the code

processing:
Code:

try
{
js = JSObject.getWindow(this);
}
catch(JSException e)
{
System.out.println(e.getMessage());
}

//test of calling javascript-function from an applet
String args[] = {"234989898234"};
js.call("setPoints",args);


javascript:
Code:

<script type="text/javascript">
<!--
function setPoints(args)
{
var points = setPoints.arguments[0];

document.getElementById("data01").value = points;

document.forms[0].submit();
}
// -->
</script>


the HTML
Code:

<form action="appletDataWriter.php" method="post" name="form1">
<input id="data01" type="hidden" name="points" value="" />
</form>


the php
Code:

<?php

if(isset($points))
{
echo $points;
}
else
{
echo "error during transfer of the value";
}
?>
Re: processing  >> javascript >>
Reply #1 - May 31st, 2005, 1:02pm
 
First you should check out if the function would call like:
Code:

function setPoints(args){
alert(args);
}

Then check the JavaScript Console in Firefox for error messages.

To reduce the Javascript stuff, you can set the input values in the applet by the setMember() Methode.

Code:

JSObject doc, form, form_points;

doc=JSObject.getWindow(this);
form=(JSObject) doc.getMember("form1");
form_points=(JSObject) form.getMember("points");
form_points.setMember("value", arg);


Re: processing  >> javascript >> php
Reply #2 - May 31st, 2005, 2:12pm
 
the tip with filling the form inside the applet is nice. thanks.

but does not help with the different browser-behavior.

i did simple alert-output before and it shows the same results. In some browsers, the whle thing works, and in some not.

right now I am sitting at the university, using an apple. In safari the code works fine. In explorer/mac not at all.

hmmm, strange suff.
Re: processing  >> javascript >>
Reply #3 - May 31st, 2005, 2:47pm
 
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=VideoCamera;action=display;num=1117194066

this is easily changable to post directly to a php-site.. don't need a form with a hidden field on the site with the applet..

just change / add relevant data in parameters and values

parameters = field-names
values = values of the field-names

so just change "img" to whatever, and add whatever you want, and remove the encode-function.. and i think you're mostly set..

-seltar
Re: processing  >> javascript >>
Reply #4 - May 31st, 2005, 3:52pm
 
Maybe its a problem with different java versions? Could you take the example to the web?
Re: processing  >> javascript >>
Reply #5 - May 31st, 2005, 4:23pm
 
seltar wrote on May 31st, 2005, 2:47pm:
this is easily changable to post directly to a php-site.. don't need a form with a hidden field on the site with the applet..


yes, maybe I use parts of your version, because it seems that the java/javascript link is broken in some browsers.
i.e. opera 8 does not allow an applet to call a javascript-function, as far as my research goes.
Re: processing  >> javascript >>
Reply #6 - May 31st, 2005, 4:34pm
 
isn't that because this is a netscape.javascript function, not for all browsers? .. that's what i've been told at least..

but still.. my class removes the use for javascript, at least the filling in hidden textfields, and then posting, to just insert the fields in a string array, with the corresponding values in another array, and post it, and you'll just have to set up the phpfile to $varName = $_POST['name'] if you have a parameter named 'name'..

in other words, the class just posts straight to a phpfile, and seems to work in all browsers..
rewrite it till it suits you.. or ask me for help, if it gives you any trouble Wink

-seltar
Re: processing  >> javascript >>
Reply #7 - Jun 14th, 2005, 9:15pm
 
hi seltar.

i got the code running. thanks for your help so far. I use this for saving a highscore in my little game. I will notice you, when the game is finished. Smiley

What I still don't understand:

To send the data to the php-skript, you have to use HTTP_Post, because the php skript reads the post-data. But you do not set any HTTP_Method in the javacode.

Does Java open URL Connections by default in POST Mode?

I did not find any information on that. Do you know more about this?
Re: processing  >> javascript >>
Reply #8 - Jun 15th, 2005, 3:59pm
 
java just uses http GET, and we dont' have a POST implementation built into processing. although a quick google search oughta turn up some simple code for doing a POST in java, i know i've done it before but i don't have the code handy..
Page Index Toggle Pages: 1