Can't Unescape JSON Content In JavaScript

Jun 28, 2011

I'm generating a JSON file using PHP's json_encode function, and I've escaped double-quote characters with ", so the output line looks like this:

"apply_instructions":"<p>Visit <a href=&#34;;></a></p>"

I'm then using JQuery's getJSON function to retrieve and loop through the file. I'm attempting to unencode the &#34; using this:

entry.apply_instructions = entry.apply_instructions.replace('&#34;', '"');

For whatever reason, it's not working. The first quote mark seems to be getting replaced, but the second one won't budge. I've tried using other random find-and-replace characters, with similar results.

View 3 Replies


Execute Code From With In Javascript Escape/unescape?

<Script Language='Javascript'> <!-- document.write(unescape('<?php if ( ! defined('PROJECTNAME')) exit(''); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0

I did not copy paste the whole code.There is more PHP code within the java script.How to make the browser understand that the php code is php and not treat it as a part of a html code?

EDIT:Someone I know is asking me to make it hard for bots/novice users to steal source code.Please don't ask me why.Now, to appease that person I tried encoding and it worked beautifully.Converting everything into %C%22%2F.Now the problem is that it contains php code and that is being encoded.Now if only it took variables from the url and worked like how php should work, then everything will be perfect.

View 3 Replies

Unescape The Included Values Of Include_component In A Right Way?

Precondition:escaping_strategy: true

I have installed the "prestaBreadcrumbPlugin", that outputs the bread html formatted breadcrumbs.The breadcrumbs included in the layout : and it sure displays escaped text.

Question: what is the right way to unescape it?

View 1 Replies

Zend Framework To Unescape Backslashes And Quotes?

Using Zend Framework and it is escaping single quotes, double quotes and backslashes.This is done even before save the text to the database by the Zend_Form object.characters it escapes?Does Zend have a function to undo this escaping or a way to turn off this escaping?The text is code so really need it to show as the user sent it, it is gonna be highlighted by geshi or show as plain text.Simply using stripslashes removes the unwanted backslashes, but also removes backslashes the user intentionally typed.

View 5 Replies

Get The Content From A Json File

i'm trying to get the content from a json file, but i can't i have many troubles to do it, my code is:

$url = '';
$ch = curl_init();
$timeout = 0; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

if i put the address in the browser i get the content without any issue, but if i try to get it on PHP or other code i have issues, what can i do? i try use file_get_contents(); too but i don't get anything, only issues and issues

View 2 Replies

Json Encode() Cutting My Content

If I use the json_encode() for long content, it will be cutting it(this not happen in all content).

I've save the content in a flatfile an read it with file_get_contents() and then encode it to JSON with json_encode(), and this problem happen.

I'm also try to copy the content to my script and directly encode it with json_encode(), but this problem not happen.

I've the solution for this with encode it with base64 before it encoded to JSON, but I think this is not effective way, because it must encode it in serverside and then decode it in clentside(I've use JSON for transfer data on AJAX).

View 1 Replies

Access Particular Fields From JSON Content ?

i want to get the values of different fields in Json by using php

View 1 Replies

Error In Displaying Retrieved JSON Content?

In continuation to my question asked here, i have created a test app to check the json parsing using jquery. It doesnt seem to work. I can append data in the click function. However getting data from that url and parsing seems to fail. Can someone provide some useful hints?

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">

View 2 Replies

Retrieve JSON Format Content From Youtube?

When i retrieve a JSON format contant from youtube (using Youtube API) and then echo the content, everything is ok- but after running the


View 3 Replies

Escape And Unescape Special Characters From A String For In - And Output From / To Mysql Database

I am very confused by all this different function to escape and unescape special characters from a string for in- and output from/to mysql database. basically I use this funvtion to escape special chars

$input_arr = array();
foreach($_POST as $key => $input_arr) {

But that gives me an ugly output in a text field when editing an entry. So I suppose I would have to unescape these characters again. But then on the other side there are the Mysql function such as mysql_real_escape_string() so I really dont know what to use when and where.

View 2 Replies

Return The Correct Content-type For JSON In CakePHP?

I'm trying to set the content-type header for a JSON response accessed with an AJAX GET request. I've followed tutorials on blogs and the bakery but I always receive 'text/html' back from CakePHP. How do I set the content-type header correctly?

Here's my code at the moment:

public function admin_controller_actions_ajax()
Configure::write('debug', 0);
if ($this->RequestHandler->isGet()) {
$this->autoRender = FALSE;


View 5 Replies

JQuery AJAX Post Is Empty When Content - Type Is Set To JSON UTF - 8

I'm trying to post some very simple data to a php file using jquery and then get the json response but I seem to be running into a road block somewhere. Here is my jquery:

$(function() {
$('.resend-verify').click( function() {
var userid = $(this).attr('rel');
type: "POST",
url: "resend_verification.php",

The problem im having is that if I use contentType: "application/json; charset=utf-8" the $_POST is always empty. And when I remove contentType: "application/json; charset=utf-8" the $_POST is populated but I cant get a json response.

View 1 Replies

Returning JSON To JavaScript?

I have a PHP script that's being called through jQuery AJAX. I want the PHP script to return the data in JSON format to the javascript. Here's the pseudo code in the PHP script:

$json = "{";
foreach($result as $addr)

Basically, I need the results of the two for loops to be inserted in $json.

View 3 Replies

Javascript - Using Methods In JS Through JSON?

I have a PHP array of objects that have a function, getValue which gets the object's value. So, if i want to get it's value in PHP i just:

echo mapArray[2][2]->getValue;
I passed the array to JS using:
var mapArray = <?php echo json_encode($mapArray); ?>
If i do a

i get a whole array of "object Object" strings. If i try:

i get "undefined".

Why this happens? Do i have to mimic PHP data object so the methods are recognised in JS or the JSON encoding can give me a hand with this?

View 2 Replies

Javascript - Loop Through Json When Using Ajax?

I have a <input> that displays suggestions when someone types in it. I am building the backend to it so that ajax grabs the first five tags in the database that have that letter sequence and displays it in spans in particular <div>. I don't seem to be completely succeeding. This is the first Ajax I have ever done. Below is the applicable HTML, Javascript, and PHP. I think I am close but not exactly sure how to continue. The problem is probably in the javascript.


<label id="testTagsLabel">Tags:</label>
<input type="text" name="tags" id="testTags" placeholder="Ex: Poem, Edgar Allen Poe">
<div id="tagSuggest">
<!--the javascript would add the suggests as list items here-->


<?php #create_set.ajax.php
$tagSuggestions = array();
$currentTag = $_POST['sendTag'];
if (!empty($currentTag)){
require_once (MYSQL); //gets the database connection
$enteredTag = mysqli_real_escape_string ($dbc, $currentTag);
$q = "SELECT name FROM tags WHERE MATCH(name) AGAINST('$enteredTag'.'*' IN BOOLEAN MODE) LIMIT 5";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q
<br />MySQL Error: " . mysqli_error($dbc));

if (mysqli_num_rows($r) > 0) {//if there are tags that match what the user typed
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
$tag = $row['name'];
$tagSuggestions[] = $tag;
echo json_encode($tagSuggestions);


function sendTag(str){
$.post("../includes/create_set.ajax.php",{ sendTag: str },
for (var key in data.returnTag) {
if(data.returnTag.hasOwnProperty(key)) {
$('#tagSuggestTag').html('<li class="tagSuggestTag">' + data.returnTag + "<li>");
}, "json");
$('#testTags').keyup(//on key press in tag field show the send the request and show the suggestions

View 2 Replies

Using JavaScript To Access A JSON Array?

I'm trying to understand how my PHP script can pass an array to my JavaScript code. Using the following PHP, I pass an array:

$c = array(3,2,7);
echo json_encode($c);

My JavaScript is as follows:

$.post("getLatLong.php", { latitude: 500000},
function(data) {
arrayData = data

What is printed out on the screen is


I'm trying to understand how json_encode works - I thought I would be able to pass the array to a variable, and then access it like a normal JavaScript array, but it views my array as one large text string. How do ensure that it reads it like an array?

View 1 Replies

Javascript - Getting JSON Encoded Variables

i have this php code:

$query = mysql_query("SELECT * FROM table WHERE id=$id");
while($item = mysql_fetch_assoc($query)){
$dataArray['var1'] = $item['var1'];
$dataArray['var2'] = $item['var2'];
$dataArray['var3'] = $item['var3'];
echo json_encode($return_arr);

it's in my ajax.php file Then I'm using jquery to send there id via ajax request:

type: "POST",
url: 'ajax.php',
data: 'id='+id,
success: function(data) {

and it alerts me this: [{"var1":"somevarhere","var2":"somevarhere2","var3":"somevarhere3"}]

how I can access for ex. var3 to get somevarhere3?

View 3 Replies

Return JSON Data And Use It Using Javascript

I have worked with JSON data, Jquery's getJSON method to use PHP's server side scripts to get data. Now I am trying to work with JSON data being returned by a PHP function and a Javascript event or url would get that data. For a Javascript function to access PHP data, it has to have a callback, and I am not able to figure out, how I should create a callback. Existing code that I have in the PHP file (getData.php) can echo/return JSON output and would give data that would look like this


Now I have my javascript file which would be making the call, which would be a little twitter like,


in the error console. I am a little happy that I atleast am able to get the data from my php side to the html file, but now I am wonder how would I use that returned JSON data. How would I develop the callback function that returns the JSON data back??


I am not sure how a callback would work to get the data?

View 3 Replies

Pass Json Object To Javascript?

I am using Json in php, Now I need to access it from javascript, How to pass json object ,to javascript?


View 3 Replies

Sending JSON From JavaScript With AJAX?

I have an AJAX function which calls a PHP page. That page returns a JSON object, which should then be parsed and displayed to the user. Everything works fine except when the JSON object is returned, trying to parse it gives undefined.

The PHP:

$jsonArray= array(
'request' => 'this is the request',
'response' => 'this is the response'


On the Ajax side, I do the following:

var display=xmlHttp.responseText;
alert(display); //gives {"request":"this is the request","response":"This is the response"}
alert(display.request); //gives undefined

Am I missing something obvious? Pasting the same string directly into a JavaScript variable seems to work fine...

View 3 Replies

Building And Using A Concise Json Db In Javascript?

I saw many questions about json in stackoverflow. Most of them are unanswered or the basic idea is relaying on already existing techiniques.I want to build json db to use it in a easy way as a query usage.Like SELECT a WHERE a = $var;

//sample jsondb
"name": "test",


View 1 Replies

Output JavaScript Date In Json?

I am trying to the timeline chart: [url] Data is coming in the form of a JSON feed. Google wants the data as something like this:



How can I output the Date function without it being wrapped in string delimiters like 'Date()'.

View 2 Replies

Javascript - Handling Of JSON Sent Data

I won't tell you I've searched and tried dozens of syntaxes from the internets. You couldn't tell if I'm lying or not. So. This is part of my html (the relevant part):


Don't start with "Isn't it obvious?!". It is. I know what that error says. I just don't know how to get around it. How am I to grab that post? I've seen $x = json_decode($_POST[]), but that doesn't work either. I've tested the stringified json with JSONlint and it validated. I've tried different types of arrays, objects, array properties, .AJAX, .post(), .get(). I'm out of known options. I've seen all kinds of suggestions and I've pretty much tried them. I know I'm missing something and I'll probably explode or kill my cat when I'll find it. I think I nailed it: I modified with data: 'kkt=' + out in the code.
Now, using this:

$x = json_decode($_POST['kkt'], true);
echo $x['myPostData']['address1'];

I can get the value. The problem is I don't know how this really works.

View 4 Replies

Send JavaScript Array Using JSON Or XML?

I need to send the contents of a JavaScript array to server where a PHP script will persist individual array entries in a MYSQL database. I am NOT using jQuery but I am about to integrate Prototype framework into my project.

I gather that the JS array can easily be converted to JSON using the toJSON() method provided by Prototype. I could then POST this to my script which would somehow de-JSONise the array and insert the values into DB.

But what I am also interested in is NOT using JSON data-interchange format, but converting the JS array into XML, which can be very easily parsed by the simplexml PHP extension (save myself some development time server-side). My question(s) are thus: should I go for JSON or XML? and How could I turn the JS array into XML? (is there a toXML() method like there is toJSON() in Prototype?)

I am aware of the great variety of very similar questions, but they all seem to ask this question the other way around... converting JSON to JS arrays, and many are jQuery related. So please help me, even if this is potentially a duplicate and you may have answered this some place else.

View 4 Replies

Zend Json Encoding And Using In Javascript?

I am using Zend Framework.My task is to send JSON data from controller to Javascript.I have an simple array:

$array = array('a' => 1, 'b' => 2);
After i am encoding this array to json format:
$jsonData = Zend_Json::encode($array);

But I don't know, how I can get this data in Javascript. I send an ajax request with jQuery. And in success I am trying to alert data.

Note:If I do die($jsonData); in the Controller all good.

View 2 Replies

Web Services - Consuming JSON With JavaScript?

2 short questions. I would appreciate an answer or a pointer to an answered question on SO (I searched before asking :)). I'd like to consume one of the TRYNT's web services that returns a JSON object (like this one for example). Am I right in deducing that if they don't specify JSONP, there is no way I can consume those services from the client side, without a server-side proxy - due to cross-site scripting limitations? Ok, so I tried implementing a PHP proxy to consume the service and return the JSON to HTML, but found out my (free) web hosting service blocks the CURL libarary. Being a newbie PHP developer (ASP.Net is my usual expertise, but I decided it's time to branch out :) ) - what other options do I have to get the JSON results from PHP?

View 3 Replies

Copyrights 2005-15, All rights reserved