Jump to content

posting html/code snippets via ajax, getting unknown error


The14thGOD

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.