I am trying to display Redis data in the browser using Webdis and jQuery. Redis and Webdis are working correctly from the command line (using curl), but I cannot get the data to display in the browser. Webdis responds with JSON and the curl response is {“GET”:”103″}. Anyone know the problem? Suggestions for improving any of this are welcome. Thanks!
The code is below:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- load JQuery from Google API -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
<!-- This is the jQuery template for the JSON returned by Webdis -->
<script id="webdisTemplate" type="text/x-jquery-tmpl">
<li>${GET}</li>
</script>
<!-- jQuery Ajax request through Webdis that feeds the Redis data into the template -->
<script type="text/javascript">
$(document).ready(function()
{
$.ajax({
url: "http://127.0.0.1:7379/GET/value",
data: "format=json",
dataType: "json",
success: function(data)
{
$("#webdisTemplate").tmpl(data.items).appendTo("#placeholder");
}
});
});
</script>
<title>Webdis Test</title>
</head>
<body>
<h4>Value:</h4>
<ul id="placeholder"></ul>
</body>
</html>
The answer is a little late but I guess it can be useful to other people to.
I used two machines so if there was any CORS problem it should rise, I didn’t
had any problem with it though. My snippet snows how to get data though $.ajax,
if you still face the problem let me know in order to expand the answer.
In your js code:
Hope it helped!