« Back
You are in :
Recent Topics »
Using jQuery Plugins »
Classis ASP integrating Async Treeview Plugin using getJSON. Stops working when using response.write [variable name] instead of simple JSON string
In order for JSON to be valid, it must use double quotes, not single quotes. Also, it is preferable to avoid manually concatenating JSON strings together yourself, if the option exists to serialize it in your backend.
Thanks very much; I agree about the serialization server side.
I just replaced all single quotes with double quotes, and the JSON string that is produced is as follows:
[{"text": "Cat1.0","id":"1"},{"text": "Cat1.1","id":"2", "hasChildren":true},{"text": "Cat1.2","id":"3"}]
Unfortunately, I'm still observing the same behavior i.e. when I response.write that string, no treeview is produced, yet when I simply past that string in the body of the asp page, the tree is created as I would expect.
It really seems like this has something to do with the response object.
Thoughts anyone?
*bump*
This code is still not working properly. Can anyone give me a hint as to why?
It would really help to see this in action. If possible, put it online and let us check.
-- Aivo --
-- Aivo --
You will be prompted to login:
username is admin
password is pass
Now "authenticated," refresh the above link and you'll see a blank page which should, by all I can figure have a simple tree control on it.
Here is the code that sets up the treeview:
<link rel="stylesheet" href="/js/jquery-treeview/jquery.treeview.css" />
<link rel="stylesheet" href="/js/jquery-treeview/red-treeview.css" />
<link rel="stylesheet" href="/js/jquery-treeview/demo/screen.css" />
<script src="/js/jquery-treeview/lib/jquery.js" type="text/javascript"></script>
<script src="/js/jquery-treeview/lib/jquery.cookie.js" type="text/javascript"></script>
<script src="/js/jquery-treeview/jquery.treeview.js" type="text/javascript"></script>
<script src="/js/jquery-treeview/jquery.treeview.async.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#categorytree").treeview({
url: "/dbadmin/includes/incCategoryAJAX.asp"
})
});
</script>
I have a <ul> elelement with the id="categorytree" on the categories page. Again, it works properly when I simply take the output of the incCategoryAJAX.asp page and paste it in the body of that same page, commenting out the response.write.
There has got to be something in the response.write that is not making the content available or not correctly encoding the content for the jquery code that needs to interpret the JSON string.
Your problems start from invalid xhtml. In xhtml, tag names are case sensitive. Doing this is wrong:
- <FORM ACTION="/members/Login_Validate.asp" METHOD="POST" name="frmLogin">
Then I see something like that returned from AJAX request:
<!--[{"text": "Cat1.0","id":"1"}, {"text": "Cat1.1","id":"2", "hasChildren":true}, {"text": "Cat1.2","id":"3"}]-->Why xml comment? That is invalid JSON. Fix and try again.
-- Aivo --
Ok, fixed those issues. It still is not working. Anything else it could be?
Now your response is empty.
-- Aivo --
-- Aivo --
If you visit this link, you will see the JSON string being produced
Yea, but on your page, you request http://icandothisandthat.com/dbadmin/includes/incCategoryAJAX.asp?root=source
-- Aivo --
-- Aivo --
I guess I'm confused about what you are saying is incorrect. I have commented out my response.write line in incCategoryAJAX.asp and have pasted the JSON string in the body of that asp page.
You will notice that the http://icandothisandthat.com/dbadmin/categories.asp page now correctly display a treeview control. Mind you, the JSON pasted in the body of the incCategoryAJAX.asp page is the same JSON it produced before I commented out the response.write line.
Hopefully, this outlines my confusion and allows you to formulate the following question, "Why would the treeview work properly when the JSON produced by incCategoryAJAX.asp is pasted in the the page body, but not when the JSON content is written programmatically with a response.write?"
This is why I feel there is something weird (or at least, unknown to me) happening with the response.write.
What I am saying is that you output json on
http://icandothisandthat.com/dbadmin/includes/inccategoryajax.asp?rootid=source
http://icandothisandthat.com/dbadmin/includes/inccategoryajax.asp?rootid=source
Two wrongs don't make one right in that case. Fix your url and asp page and it sould work.
-- Aivo --
I see where the miscommunication was and have fixed the problem. As you mentioned, fixing the parameter fixed the problem. I appreciate your time to show that to me.
Post Actions

