Sending " characters with Ajax

Hello,

No problem sending data with ajax

The problem is:

Double quotes character " in content causes problems
How do I get around the double quotes character problem?
cifttirnak

It shouldn’t cause problems. Can you share the code you use to submit the code and handle it server side (both js and php)?

Happy birthday

This code " double quotes problem

$(document).ready(function(){       
    $('form').submit(function () {
 
         var mesaj = $("#txtEditor").Editor("getText");    

    var str = 'grup=1&mesaj=' + mesaj;
    var t = $('#toplu_mesaj').serialize();
    (t !='')? str += '&'+t :'';
			$.ajax({
				url: "topluemailgonder.php",
				type: "POST",
                data: str,
			   cache: false,   
		   	 success: function(dataResult){
	       alert(dataResult);
				}
			});
            
        });
    });
    
</script>

The following code does not cause problems
However, some characters have been deleted in the data

<script type="text/javascript" language="javascript">	
     
      function gonder() {
 
         var mesaj = $("#txtEditor").Editor("getText");

    var str = 'grup=1&mesaj_icerigi=' + mesaj;
    var t = $('#toplu_mesaj').serialize();
    (t !='')? str += '&'+t :'';
			$.ajax({
				url: "topluemailgonder.php",
				type: "POST",
         data: str,
			   cache: false,   
		   	 success: function(dataResult){
 	       alert(dataResult);
				}
			});        
    }
    
</script>

<input type="submit" class="button"  id="button-confirm" onclick="gonder();return false;" value=" Gönder "/>

Output
topluemailgonder.php
echo $_POST[‘mesaj_icerigi’];
Remove +(s)

I solved the problem

var mesaj = encodeURIComponent(mesaj);

Sponsor our Newsletter | Privacy Policy | Terms of Service