Author Topic: JSON/AJAX  (Read 2869 times)

0 Members and 1 Guest are viewing this topic.

Offline LordConiupiter

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 339
  • Rating: +3/-0
  • Just one of the thousands of Axe-fans...
    • View Profile
JSON/AJAX
« on: December 27, 2010, 07:14:38 am »
This is a thread I started because I just discovered JSON as a great way of creating webpages which need to update using new information from the server. I already have written a javascript which makes it even easier to request info from the server. An example is attached. If you don't know how to test  them, here is a program freely available for download. Copy the example files in the USBWebserver/root directory, and start usb webserver8.exe or somthing like that. You also could use XAMPP, which will perhaps do the job even better, but I just downloaded that program today, because a schoolmate of mine recommendet it, since is also has a Linux version. (wow, that's a long sentence :P )

BTW: the attachment is zipped with 7zip compression, which is done by jZip. I've done this because it's the smallest an fastest compression I ever saw. Decompression can be done using winRAR, jZip or 7zip, and even lots and lots more applications I don't know of.
« Last Edit: December 28, 2010, 06:02:58 am by LordConiupiter »
everytime that I was down, you would always come around, and get my feedback on the ground. (modified part from 'Seasons in the sun')

No matter how many errors are bothering you, always try to stay rel-Axe!

The HoMM project will be resumed as soon Axe 1.0.0 will be released!
Projects:
Code: [Select]
HoMM:   [==--------]    Project 'resumed': I'm suffering overwhelming new ideas being popped up in my dreams :P
tiDE:   [----------]    Explored and understood the main part of the code: just started writing a Tokenizer.



password of the week: uvanapererubupa (Any pronunciation is the right one ;) )   :D click me, and you'll be raided :D

Offline Ikkerens

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 378
  • Rating: +28/-9
  • JavaScript Magician
    • View Profile
    • Walotech
Re: JSON/AJAX
« Reply #1 on: December 27, 2010, 09:17:31 am »
I don't know what exactly you're intending to do using this kind of client/server communication, but there are several things I'd like to point out:
*I see you're using a self written piece of code to send ajax requests (GET), instead I'd using a already given library, such as jQuery or MooTools, although i'd recommend jQuery, as the mootools project is discontinued.
Upside of mootools however is, that the code is understandable, many people don't understand the entire jQuery code.

*Creating a client-side query and the sending it to the server is a MAJOR security leak.
Unless you're going to use the program for private use, any user that could get past your code CAN and most likely WILL search the DOM for leaks.
This isn't a leak, its a hole in the wall, just sayin'.
Because this, basically, gives any user the privilege to execute MySQL query's without the need of your password/host/username and stuff.

*json_encode and json_decode are not supported on every server, if you're ever going to release your code, you might consider including the following code:
http://walotech.com/jsonsource.php

Below that code you see a part written by me, allowing support for any server, only defining the functions if they don't exist :)
« Last Edit: December 27, 2010, 09:32:43 am by Ikkerens »

Splut for Android [----------]
Paused/halted indefinitely, might be abandoned, our graphic designer quit and the rest of us simply doesn't have the time to work on it...

Offline LordConiupiter

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 339
  • Rating: +3/-0
  • Just one of the thousands of Axe-fans...
    • View Profile
Re: JSON/AJAX
« Reply #2 on: December 27, 2010, 04:04:39 pm »
I don't know what exactly you're intending to do using this kind of client/server communication, but there are several things I'd like to point out:
*I see you're using a self written piece of code to send ajax requests (GET), instead I'd using a already given library, such as jQuery or MooTools, although i'd recommend jQuery, as the mootools project is discontinued.
Upside of mootools however is, that the code is understandable, many people don't understand the entire jQuery code.

*Creating a client-side query and the sending it to the server is a MAJOR security leak.
Unless you're going to use the program for private use, any user that could get past your code CAN and most likely WILL search the DOM for leaks.
This isn't a leak, its a hole in the wall, just sayin'.
Because this, basically, gives any user the privilege to execute MySQL query's without the need of your password/host/username and stuff.

*json_encode and json_decode are not supported on every server, if you're ever going to release your code, you might consider including the following code:
http://walotech.com/jsonsource.php

Below that code you see a part written by me, allowing support for any server, only defining the functions if they don't exist :)

The intention is to load certain database data unto the client in javascript, so it can be ordered easily without needless server requests.
*I have seen the jQuery library, but I still like to code things myself, and even create my own library.
*The client side queries you saw are not sent to the server. When you look deeper in the code, you'll see those queries are coverted to javascript conditions, and used for getting data from the loaded databasepart.
*Thanks, but I knew was it was supported since PHP 5.2 or so, so that's a prequisite. Perhaps I should have mentioned that in my first post. With this piece of code I can make it more generally usable!

Thanks for the feedback! Don't hesitate to give me more if you have. Feedback optimizes, and comments keeps alert(!)
everytime that I was down, you would always come around, and get my feedback on the ground. (modified part from 'Seasons in the sun')

No matter how many errors are bothering you, always try to stay rel-Axe!

The HoMM project will be resumed as soon Axe 1.0.0 will be released!
Projects:
Code: [Select]
HoMM:   [==--------]    Project 'resumed': I'm suffering overwhelming new ideas being popped up in my dreams :P
tiDE:   [----------]    Explored and understood the main part of the code: just started writing a Tokenizer.



password of the week: uvanapererubupa (Any pronunciation is the right one ;) )   :D click me, and you'll be raided :D

Offline LordConiupiter

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 339
  • Rating: +3/-0
  • Just one of the thousands of Axe-fans...
    • View Profile
Re: JSON/AJAX
« Reply #3 on: December 28, 2010, 06:05:06 am »
New update! Now you can write your data into any type of HTML you want!
New code is über-commented!
everytime that I was down, you would always come around, and get my feedback on the ground. (modified part from 'Seasons in the sun')

No matter how many errors are bothering you, always try to stay rel-Axe!

The HoMM project will be resumed as soon Axe 1.0.0 will be released!
Projects:
Code: [Select]
HoMM:   [==--------]    Project 'resumed': I'm suffering overwhelming new ideas being popped up in my dreams :P
tiDE:   [----------]    Explored and understood the main part of the code: just started writing a Tokenizer.



password of the week: uvanapererubupa (Any pronunciation is the right one ;) )   :D click me, and you'll be raided :D

Offline Ikkerens

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 378
  • Rating: +28/-9
  • JavaScript Magician
    • View Profile
    • Walotech
Re: JSON/AJAX
« Reply #4 on: December 29, 2010, 06:25:22 am »
Allright, it's getting somewhere now.
I just don't get 1 thing, why did you include jQuery.js?
It's not used in any document :S
P.S. Het engelse woord yet wordt geschreven met een griekse y :), zag namelijk jet in je code staan :P
« Last Edit: December 29, 2010, 06:29:31 am by Ikkerens »

Splut for Android [----------]
Paused/halted indefinitely, might be abandoned, our graphic designer quit and the rest of us simply doesn't have the time to work on it...