views:

92

answers:

2

Update:

It looks like the problem is when I'm reading the value from the html to begin with.

This is the markup:

<input name="someval" type="text" value="Receive (+ open)" />

I'm reading the value of someval like this and passing it to the ajax call:

    $.ajax({

        data: 'someval=' + $("input[name=someval]").val(),

        success: function(resp) {
           $("#targetd").html(resp);
           alert(resp); 
        }
});

Looks like the problem happens when it concatenates $("input[name=someval]").val() to data: 'someval=' + since $("input[name=someval]").val() has a + in it.

Old

I'm making an ajax call to a php script and the response returned contains html markup. I take that response and assign it to a div after that.

success: function(resp) {
   $("#targetd").html(resp);
   alert(resp); 
}

Part of the response being returned is supposed to look like this. (notice the + sign)

<input name="someval" type="text" value="Receive (+ open)" />

It's working fine and I can assign it to the div, except that for some reason the markup returned is missing the + sign

<input name="someval" type="text" value="Receive (  open)" />

When the php script itself outputs the markup, it works fine, but when the markup is passed to the page through an ajax response the + disappears. I'm not doing anything special to the markup, as the code above shows, I'm just taking it as is as soon as it's returned and assigning it to the div. When I alert the response directly, the + is also missing so not just when it gets assigned to the div. Not sure what could be going on here.

+1  A: 

I recommend trying to escape your plus + as &#43; and see if that solves your problem. If it does, its a entity escape problem.

tooleb
Thanks tooleb, I gave it a try, but unfortunately didn't work. +1 though for the attempt to help out.
Chris
So if you initially had "Recieve (+ open)" as the value and you tried your code, what was the result, just curious?
tooleb
It was still missing the `+` but as it turned out it's because it hadn't received it to begin with. I'm reading the value of `someval` first, then giving it to the php to output again. I've updated the question to reflect the recent troubleshooting.
Chris
If you encode the value before passing it in the data variable, it will work. Try using Phil's encode function
tooleb
+1  A: 

Did you try HTML encoding the response? I use these functions in my javascript to encode/decode.

function HtmlEncode(value)
{
    return $('<div/>').text(value).html();
}

function HtmlDecode(value)
{
    return $('<div/>').html(value).text();
}
Phil Derksen
Thanks Phil, that's good info too.
Chris