First of all, please learn to post. NetNews is thread-based; you should
post a followup to the text you are directly referring to, provide
attribution of quoted material (in Google Groups: show options, Reply),
and trim your quotes to the minimum necessary to retain context:
<URL:
http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
That said, for the flaw in its Web interface, posting with Google Groups is
recommended against anyway. Use a decent newsreader application instead.
___________________________________________________________________________
(e-mail address removed) wrote:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You better use your name here.
Ok, thanks for the replies although a lot of it was over my head. I
have been learning web scripting for 3 or 4 days now so be please dumb
it down a bit.
I will try. However, never hesitate to ask explicitly about things you do
not (fully) understand.
I think my problem is
[Julian Turner wrote:]
(b) when you extract the contents of a TEXTAREA using the BOM, the
Javascript String does not contain all of the "special characters" you
expect it to. In which case, can you be explicit as to which
characters are causing a problem for you. A Javascript String consists
of 16bit characters, and so can represent unicode values from 0000 to
FFFF I think.
and it is the "+" symbol that I seem to be missing, at least thats the
only one missing from my short test latex file.
Because you are including it in the request URI, even though you are
using POST. The plain `+' character is considered a substitute for the
space character in the query component by many server-side applications,
including PHP.
[Thomas 'PointedEars' Lahn wrote:]
(La)TeX source is plain text, I do not see why that would be relevant.
Are confusing the source code with the output it generates?
When I say special characters I mean things like "+/!$&<" not things
like alpha, beta, gamma etc you see in LaTex output.
Of those characters, only `+' and `&' can be considered special, and only
within the query component of a URI. (See above for the `+' character.)
The `&' character is the delimiter between each parameter of the component,
so it must be escaped if it does not serve as such (see RFC3986; you do
this already).
I believe my problem may lie in either the way I am retrieving the
contents of the textarea or in the way i am saving it to a file.
Your assumption is correct.
The DOCTYPE declaration is missing before this, so the markup is not Valid.
<head>
<script language="javascript" type="text/javascript">
You can safely omit the deprecated `language' attribute. You must omit it
with a Strict (X)HTML document type.
function loadtex(url){
var xmlHttp = new XMLHttpRequest();
See below.
xmlHttp.open('GET',url,true);
xmlHttp.onreadystatechange=function(){ setsource(xmlHttp); };
Unless you are planning to reuse setsource() somewhere, there is no need to
call it. You can simply use its code as code of the anonymous function.
xmlHttp.send(null);
}
function setsource(xmlHttp){
if(xmlHttp.readyState==4){
if (xmlHttp.status==200){
var response = xmlHttp.responseText;
document.getElementById("texSource").value=response;
Use a `form' element to contain the form controls, and pass `this.form' as
second argument to the method, say `f'. Then you can refer to the control
within the method by
f.elements['texSource'].value = response;
However, you would not need the "texSource" ID here:
f.elements['tex source'].value = response;
("tex source" is the current name of the control) would work as well.
}
}
}
function savetex(){
var updtSrc = escape(document.getElementById("texSource").value);
See above.
var urlS = 'save.php?content='+updtSrc;
You are doing this the wrong way.
Although specified different, there is a limit on URI length in some
browsers (IE is especially restrictive here). So on request what is
properly evaluated from 'save.php?content='+updtSrc by the script
engine is truncated for longer LaTeX code anyway.
var svHttp = new XMLHttpRequest();
This will not work in Internet Explorer before version 7 beta 2+.
See said:
svHttp.open('POST',urlS,true);
Using POST is the correct approach to work around the URI length limit,
however then you do not need to use the query component anymore:
var urlS = 'save.php';
svHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
Opera 8+ supports XMLHTTPRequest, but Opera 8.0 does not implement the
setRequestHeader() method yet. (It is supported since version 8.01.)
svHttp.send("content=" + updtSrc);
}
</script>
</head>
<body>
<table border="1" width=100%>
Consider not using tables here, and learn to use CSS.
<tr><td><center>
<INPUT type=button value="Load LaTex Source"
onclick="loadtex('sample.tex')">
Whenever you use event handler attributes such as `onclick', you should
declare the default scripting language in the 'head' element:
<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
</center></td></tr>
<tr><td>
<br>
Do not use the `br' element to achieve margins. Use the CSS `padding' and
`margin' properties instead.
See above.
<textarea name="tex source" id="texSource", cols=80, ^ ^
rows=35></textarea>
You are confusing programming and markup language here. Commas are not
allowed within a (start) tag outside of CDATA attribute values. They may
be ignored, but one should not depend on that. Remove them.
Attribute values should always be single-quoted or double-quoted. Although
not required, maybe it is better for later element object access to replace
the space in the name with an underscore (_) or, if you omit the ID
attribute as rendered redundant by my suggestion above, just remove the
space. You should have a preference for lowercase names and IDs.
</center></td></tr>
<tr><td><center>
See above.
<INPUT type=button value="Save Source" onclick="savetex()">
</center></td></tr>
</table>
</body>
</html>
save.php
<?
$datevar=date("YmdHms");
$array1=array($datevar,'.tex');
This is unnecessary, see below.
$stuff=stripslashes($_GET['content']);
This line removes all backslashes (e.g. from "\tilde{}"):
<URL:
http://de.php.net/manual/en/function.stripslashes.php>
Do not use stripslashes() here.
Use $_POST instead of $_GET here (see above).
$filename=implode($array1);
Unnecessary inefficient. Consider
$filename = date('YmdHms') . '.tex';
instead.
$f=fopen($filename,"w");
fwrite($f,$stuff);
fclose($f);
?>
You should test whether fopen() was successful before you fwrite() and
fclose():
$f = fopen($filename, "w");
if ($f)
{
fwrite($f, $stuff);
fclose($f);
}
HTH
PointedEars