Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Run SQL in javascript

    I am quite new to using javascript and am currently trying to create a real-time username checker. Once the user enters the username I would like some javascript to run and check whether the username is already in the database, then if it is return 'this is already in use'.

    Unfortunately I am not able to use ajax.

    I would be very grateful for any help with this matter, and any example code would be much appreciated.

    Phil

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Unfortunately I am not able to use ajax.
    There's no way other than Ajax to run a serverside process using javascript.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Why can't you use AJAX, why not research how to do AJAX and then you can use it to do the real-time username checker.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #4
    New Coder
    Join Date
    Dec 2010
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DJCMBear View Post
    Why can't you use AJAX, why not research how to do AJAX and then you can use it to do the real-time username checker.
    Unfortunately the server I'm using only allows for php, and ajax does not seem to run on it.

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Quote Originally Posted by supersav144 View Post
    Unfortunately the server I'm using only allows for php, and ajax does not seem to run on it.
    It seems like you are unaware of Ajax!
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,216
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    http://www.w3schools.com/php/default.asp

    Look down the page to the section title "PHP and AJAX".

    Or just start here:
    http://www.w3schools.com/php/php_ajax_intro.asp
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    First of all, AJAX is not a language. You don't care what type of server side language you use.

    Since PHP can generate XML as result to clients' browser and client's browser allow creating http request object with javascript there shoudnt be a problem with AJAX programming

    If you really have to do something like AJAX's background http requesting without using the normal http object then consider making an invisible IFrame but its definitely not a good choice.

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,216
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    consider making an invisible IFrame but its definitely not a good choice.
    Why not?

    I did this as far back as 1998, before AJAX existed, and it worked great then. It still works great today. The big advantage is that it's much easier to debug with invisible IFrames, as you can simply turn the iframe visible while debugging and then do a view==>>source to see what's there. Plus it's often simpler to code. For example, if you want to send the contents of a <form> back to the server, all you have to do is
    <form target="MyInvisibleIFrame" method="post">
    and submit the form. No need to encode the values by hand; let the browser do it for you.

    No, it's not a good solution for working with any prepackaged library. Clearly the code done this way is only going to work in one particular circumstance. But what's wrong with that, if you are creating a highly specialized system in the first place?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Quote Originally Posted by supersav144 View Post
    Unfortunately the server I'm using only allows for php, and ajax does not seem to run on it.
    The server can't turn the usage of javascript off as it's a client-side language and since AJAX is a form of Javascript coding only the client can decide to have it turned on or off with their browser options, the server can decide what "server-side" languages to allow but (x)html, xml, css, javascript basicly all client side languages are standard, the server can decide to allow a file format which with javascript being so widely used in mark-up the blockage of .js files will never stop the developer from using javascript as they can just write the codes in the html or php files, so there isn't any way to stop the usage of it.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #10
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,302
    Thanks
    10
    Thanked 586 Times in 567 Posts
    you can use other things besides ajax to talk to php.

    1. use an image ping and php's gd to set the width of the returned image; 1=no user, 5=user exists.

    2. use a dynamic <script> tag in conjunction with a jsonp response from php's json_encode.

    3. use cookies and iframes.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •