Sending data upon receipt

I have one text box. I am sending a text area value

<textarea class="php" name="codeguru"></textarea></div> <div class="hint">This code is editable. Click Run to execute.</div> <input type="submit" value="Run" /> 

via the $ ajax method

 $.ajax({ type: 'GET', url: 'exec.php', dataType: 'JSONP', data: { code: code }, success: function (data) {}, jsonpCallback: 'mycallback', error: function (xhr, ajaxOptions, thrownError, err, textStatus) { } }); 

Problem: when I send data like echo 'sanjay'; it is transformed into an echo of sanjay.

I also implemented it on localhost and cpanel. This works fine on localhost, but not fine on cpanel. Any suggestions or ideas would be appreciated.

+6
source share
2 answers

I got my answer

 $code = stripslashes($code); 

Because of this code, I can remove the black mark

+3
source

The URL must be encoded before AJAX and decoded on the server side. This happens to me with specific characters in JSON strings, I usually URL encode it:

Value:

  $.ajax({ type: 'GET', url: 'exec.php', dataType: 'JSONP', data: { code: encodeURIComponent(code) }, success: function (data) {}, jsonpCallback: 'mycallback', error: function (xhr, ajaxOptions, thrownError, err, textStatus) { } }); 

And on the server side:

 $code = urldecode($_POST['code']); // or rwaurldecode, not sure 

Try sending the code with / and " and see how it reacts, because I had problems with them, if it tries to add slashes in quotation marks, etc. I use the following function, but you can change it to suit your needs :

 function addslashes( str ) { return (str + '').replace(/[\\"]/g, '\\$&').replace(/\u0000/g, '\\0'); } 
0
source

All Articles