The reason + gets turned into a space is because your incoming data is
being "urldecoded" (or "unescaped") by PHP, and +, just like %20, gets
turned into a space.

The reason this is happening to you when you use ajax is because when
you pass a String as the "data" parameter, it is assumed that it's
already escaped. When you don't use ajax, the browser takes care of
escaping the + for you (it is escaped as %2B). To fix your problem,
you need to change line 9 and wrap this.value in
encodeURIComponent(this.value).

But more importantly, you really don't need to be generating the
parameter string like this. You could just as easily generate a
parameter object and let jQuery deal with it. Something like:

var inputs = {};
$(':input', this).each(function () {
        inputs[this.name] = this.value;
});
...
data: inputs,
...

BUT, more importantly, I suggest you just use Mike's form plugin, found here:
http://www.malsup.com/jquery/form/

Then you could replace the whole thing with:

$('#lightning').ajaxForm({
                type: 'POST',
                dataType: 'json',
                success: function(json) {
                        // do whatever here.
               }
});

Good luck with it.

--Erik


On 8/26/07, barophobia <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> I'm having a weird issue with data being passed through $.ajax. If I
> submit my form through normal means I do not witness the unexpected
> behavior. Only when I submit the form through $.ajax does it happen.
>
> The problem is that I'm trying to submit an email address with a +
> sign in it. Firebug even says that I'm submitting
> "[EMAIL PROTECTED]" but PHP says that I've submitted "email
> [EMAIL PROTECTED]".
>
> It would seem that this is PHP's fault since Firebug reports the
> correct data. But that's why this is so weird. When I take $.ajax out
> of the loop PHP says that I have submitted "[EMAIL PROTECTED]".
>
> Here is the jQuery code I am working with:
>
> http://www.pastebin.ca/671971
>
> Maybe it's really simple and I just don't see it?
>
>
>
> Thanks,
> Chris.
>

Reply via email to