开发者

Passing a string to a javascript and retrieving it further

I am passing a string to a javascript through call by reference. The string is a text retrieved from a textarea field. The problem is that a single word is retrieved properly, but when I send multiple text it shows a problem. The sample code is like this in a php file, The txt is the name of textarea field. If I type hello in the field and send it works properly but whenever I type string like "hello india", it gives a problem and nothing is retrieved

Sample code for post.php is like this :

<?php
$msg=$_GET['msg'];
$v1=$_GET['v1'];
$v2=$_GET['v2'];
    <textarea name="txt" id="txt">
    <input type=button onclick="send(txt.value,123,456)">
?>

The send() method is not a standard method. Its a custom method which passes variables to a file through GET method. The txt is the name of the textarea column. The send method works li开发者_JS百科ke this:

function send(str,var1,var2)
{
$('#loader').html('loading');
$('#postarea').load('post.php?msg='+str+'&v1='+var1+'&v2='+var2);
}


If you use Ajax to send the string that is probably the culpritt.

Use escape(string) to URL encode the string.

Also, if you use firefox, a addon called firebug and Live HTTP Headers are gold when debugging.

With Livehttpheaders you can se every call and respons from the server even if your script should ignore them.


Please check the code below, its working fine its retrieving the data from text area correctly. i think there's some problem in the line '$('#loader').html('loading') ' u have added in JS.....

<script type="text/javascript">
function send(str,var1,var2) {
    alert(str);
}
</script>

<textarea name="txt" id="txt"> </textarea>
<input type=button onclick="send(txt.value,123,456)">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜