I call the same PHP script using $ .ajax and $ .get and get two different results.
$. ajax breaks the lines from the data passed through the function, but $ .get does not.
I tried explicitly setting the dataType type for text and html with no luck. Most options for $ .get are the same in $ .ajax by default.
http://api.jquery.com/jQuery.ajax/
This is mistake?
Here is the exact code I'm using:
$.get("lib/ajax_scripts/set-product-value.php", { input_id: input_id, val:value }); $.ajax({ url:"lib/ajax_scripts/set-product-value.php", type:'GET', data:'input_id='+input_id+'&val='+value});
Below is the code where anyone can try who has access to a server with PHP and firebug support. Look at the firebug answer for each request, you will see that <br /> added to $ .get, and not to $ .ajax.
ajaxtest.html
<form method="GET" onsubmit="return false"> <textarea id="data" name="data">a b c</textarea> <input type="submit" value="Submit" id="submit"> </form> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script type="text/javascript"> $('#submit').click(function(){ var data = $('#data').val(); $.get("data.php", { data: data }); $.ajax({ url:"data.php", type:'GET', data:'data='+data}); }); </script>
data.php
<?php echo nl2br($_GET['data']); ?>
payling
source share