tags:

views:

48

answers:

2

Welcome,

I'm using jquery to send form, via POST.

That's how i'm getting value.

var mytext = $("#textareaid").val();
var dataString = 'text='+ mytext;

Problem is, i lost somewhere '+' sign... PHP don't get it. But when i print mytext, i can see + sign.

I think it's special char and it's removed by jquery.

Does anyone have better idea then, repleace in javascript "+" with "hereshouldbepositivesign" and in php repleace "hereshouldbepositivesign" to "+" ? Regards

+3  A: 

You have to properly encode parameter names and values:

var dataString = 'text=' + encodeURIComponent(mytext);

I didn't bother to encode "text" because it's obviously safe.

You can let jQuery do it for you if your values are in a form. You don't post how you're doing the POST, but if it's with a jQuery ajax API you can set "data" to a plain object:

{ text: mytext }

and it'll know to encode it for you.

Pointy
encodeURIComponent, solve my problem.This is how i send.$.ajax({type: "POST",url: "test.php",data: dataString,cache: false,success: function(html){ }
marc
A: 

IN GET requests at least, spaces are translated into plus sign (because URLs can't have spaces), and the framework usually translates them back before giving the data to you to process.

This means you have to do something else with plus signs to get them plus signs. Normal URL encoding would make them %2B.

James Curran