4 Replies - 2745 Views - Last Post: 07 June 2010 - 11:03 PM

#1 pmiller624  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 55
  • Joined: 02-May 10

jQuery Ajax is being broken up on ampersands (&)

Posted 03 June 2010 - 12:46 PM

So here's what my Ajax call looks like:
$.ajax({
	url: 'processing.php',
	type: "POST",
	data: "title="+title+"&message="+msg,
	success: function(data){
    	        //Do stuff here
	}
 });


The data that I am posting can sometimes have ampersands in them.
An example would be

title=white & blue&message=these are colors

The problem is that because of the ampersand blue is being treated as a new variable and not part of a string. How can I safely post the variables that I need to post without them being broken up?

I have tried escape() but when I try to undo the escape on the php side it can't do it successfully.

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: jQuery Ajax is being broken up on ampersands (&)

#2 Primm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-May 10

Re: jQuery Ajax is being broken up on ampersands (&)

Posted 03 June 2010 - 01:34 PM

Try to use \&.

The \ is used to insert special characters inside a string.

Primm
Was This Post Helpful? 0
  • +
  • -

#3 BetaWar  Icon User is online

  • #include "soul.h"
  • member icon

Reputation: 1138
  • View blog
  • Posts: 7,108
  • Joined: 07-September 06

Re: jQuery Ajax is being broken up on ampersands (&)

Posted 03 June 2010 - 04:48 PM

I am not positive here, but I believe that the urldecode function is PHP's way of undoing encode (from JS), so you may want to give that a shot.

Here is the documentation on it:
http://us2.php.net/m...n.urldecode.php
Was This Post Helpful? 0
  • +
  • -

#4 pmiller624  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 55
  • Joined: 02-May 10

Re: jQuery Ajax is being broken up on ampersands (&)

Posted 03 June 2010 - 08:34 PM

View PostBetaWar, on 03 June 2010 - 03:48 PM, said:

I am not positive here, but I believe that the urldecode function is PHP's way of undoing encode (from JS), so you may want to give that a shot.

Here is the documentation on it:
http://us2.php.net/m...n.urldecode.php

I have tried what you suggested, but PHP is unable to decode the URL successfully.
Was This Post Helpful? 0
  • +
  • -

#5 psyking  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 165
  • Joined: 17-January 10

Re: jQuery Ajax is being broken up on ampersands (&)

Posted 07 June 2010 - 11:03 PM

View PostPrimm, on 03 June 2010 - 12:34 PM, said:

Try to use \&.

The \ is used to insert special characters inside a string.

Primm



Primm is right, the '\' symbol allows you to insert special symbols into strings. For example:
<script TYPE="TEXT/Javascript">
var aString;
aString = "Hello my nickname is \"PsyKing\" \& I make websites.";
//aString is then equal to: Hello my nickname is "PsyKing" & I make websites.
</SCRIPT>


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1