The14thGOD Posted October 20, 2011 Share Posted October 20, 2011 Just a heads up, my OOP skills are in development so sorry for the roughness of things...(any tips always appreciated!) I'm basically making my own little repository site that will have snippets (for quick copy paste anywhere) (I know there are other services, but mine is a little different and needs to be private). I'll try to just post the necessary code: HTML trying to pass: <p><br /><span class="something">Hey buddy</span></p> Javascript/JQuery: //send info $.ajaxFileUpload({ url:'./upload_zip.php', secureuri:false, fileElementId:'form_zip', dataType: 'json', data: {... 'description': htmlEntities($('#modularContent form textarea[name="description"]').val())...}, success:function(data, status){ var html = ... html+= ...'<div class="description"><p>'+data.description+'<br /><br />';... $('#list').append(html); ... $('#modularOverlay,#modularContent').remove(); }, error:function(data, status, e){ alert(e); } ... function htmlEntities(str) { return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); } //found via: http://css-tricks.com/snippets/javascript/htmlentities-for-javascript/ PHP: <?php //Start object and modify initial values public function __construct($title,$description,$url,$snippet){ ... if($this->snippet == 'yes'){ $this->handle_snippet(); } } public function handle_snippet(){ $code = htmlentities($this->description, ENT_QUOTES | ENT_IGNORE, 'UTF-8',false); $this->description = $code; } //returning value public function getJSON($action){ //temp fix for js breaking if remove_tag_ids is empty/null if(empty($this->remove_tag_ids)){ $this->remove_tag_ids = 'null'; } if($this->snippet == 'yes'){ $this->description = stripslashes($this->description); } switch($action){ case 'delete': //not important default: $json = array(...'description'=>$this->description...); break; return $json; } ?> POST Value: (via firebug) description: <p><br /><span class="something">Hey buddy</span></p> JSON Return value: (via firebug) description: <p><br /><span class="something">Hey buddy</span></p> DB value: <p><br /><span class=\"something\">Hey buddy</span></p> As far as error, I have no idea what the error is haha. It does not get through to the error code cause the plugin tosses an error b4 that (using an ajaxUpload plugin http://www.phpletter.com/Our-Projects/AjaxFileUpload/, (this does not affect the upload, it uploads just fine, but it tosses an error for some reason)). Anyone have any insights/ideas? Thanks for any and all help, Justin Quote Link to comment https://forums.phpfreaks.com/topic/249479-posting-htmlcode-snippets-via-ajax-getting-unknown-error/ Share on other sites More sharing options...
The14thGOD Posted October 20, 2011 Author Share Posted October 20, 2011 I should clarify, the success function never runs either, however if I reload the page, the new entry is there. Quote Link to comment https://forums.phpfreaks.com/topic/249479-posting-htmlcode-snippets-via-ajax-getting-unknown-error/#findComment-1280914 Share on other sites More sharing options...
The14thGOD Posted October 20, 2011 Author Share Posted October 20, 2011 update: ok i narrowed it down... it's gotta be something to do with the way json handles the code that is passed from PHP to javascript, I changed it to output 'code here' and it worked Quote Link to comment https://forums.phpfreaks.com/topic/249479-posting-htmlcode-snippets-via-ajax-getting-unknown-error/#findComment-1280934 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.