Re: Strange string behavior...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Don Wieland wrote:

> On Aug 13, 2014, at 11:48 AM, Christoph Becker wrote:
> 
>> escape() is deprecated[1]; it's better to use encodeURI() resp.
>> encodeURIComponent() instead.  However, in this case the Ajax request is
>> done with jQuery.ajax() so it is sufficient to set the data property to
>> an appropriate object[2].  Most likely it is even possible to simplify
>> the code considerably by using .serialize()[3].
>>
>> [1]
>> <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape>
>> [2] <http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings>
>> [3] <http://api.jquery.com/serialize/>
> 
> I am still stumped and I am not clear on how to effectively add the serialize() parameter to my javascript and even if I figure it out,  I am not certain if that is my issue.
> 
> Basically, when add an alert(data); to my AJAX code, the message is displayed perfect:
> 
> Right hip + left knee replacement, in a lot of pain, "tried everything" - wants "deep work" - last massage didn't work, rieki and feldon crais didn't work, epidural two weeks ago backfired, still in pain. -DOH
> 
> then when the ajax POST to the PHP page, it changes it to:
> 
> Right hip left knee replacement, in a lot of pain, \"tried everything\" - wants \"deep work\" - last massage didn\'t work, rieki and feldon crais didn\'t work, epidural two weeks ago backfired, still in pain. -DOH
> 
> ---------------------
> 
> when I then change the + character to a &, this is what happens,
> 
> Right hip & left knee replacement, in a lot of pain, "tried everything" - wants "deep work" - last massage didn't work, rieki and feldon crais didn't work, epidural two weeks ago backfired, still in pain. -DOH
> 
> then when the ajax POST to the PHP page, it changes it to:
> 
> Right hip
> 
> -----
> 
> This one has me stumped.
> 
> Here is the AJAX:
> 
> $.ajax({
> 			url: "/utils.php",	
> 			
> 			type: "POST",
> 
> 			data: data,		
> 			
> 			cache: false,
> 			
> 			success: function (html) {
> 				data_ar = html.split('|');				
> 				data_ar[0]=data_ar[0].replace("\n","");
> 				if (data_ar[0]=='id') {					
> 					$('.inputField').attr('disabled',false);
> 					$('.button').attr('disabled',false);
> 					$('.loading').html('');
> 					
> 					if(no_reload!='1') {
> 						//$('#apptform').fadeOut('slow');					
> 						//$('#appt_done').fadeIn('slow');
> 						
> 						loadAppt(date_start.val(),'',room.val(), clientid.val(), data_ar[1], $('#av_id').val());
> 					}
> 					//loadCalendar();
> 					//hideDialog();
> 					//alert("\""+html+"1\"");
> 					return true;
> 				} else { 
> 					$('.inputField').attr('disabled',false);
> 					$('.button').attr('disabled',false);
> 					$('.loading').html(' ');
> 					//alert("\""+html+"2\"");
> 					jAlert(html.length>0?html:'Sorry, unexpected error. Please try again later.') ;
> 					return false;
> 				};				
> 			}		
> 		});
> 
> I really see nothing in that code that looks suspicious. Although, I am not an expert in this area. How would you suggest I insert the serialize() function into this ajax call?

The jQuery documentation has a nice example:
<http://api.jquery.com/serialize/#example-0>.  I suggest you have a
closer look at it.  The return value of .serialize() can be used as
value of the "data" property of the jQuery.ajax() configuration object.

And please "reply to all" next time; a private conversation is of little
value for the other readers of the mailing list.

-- 
Christoph M. Becker

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux