Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

JavaScript question.

  • 15-02-2012 12:49pm
    #1
    Registered Users, Registered Users 2 Posts: 760 ✭✭✭


    I playing with some JavaScript.

    I want it to when I click a button that it run a php/perl file .

    I did a bit of googleing :

    http://stackoverflow.com/questions/1280767/how-do-i-run-php-code-when-a-user-clicks-on-a-link

    So I deiced to to test .

    Installed jquery to the same directory as the webpage .

    But it not working , I not a javascript guru, I just playing with it .

    here my code
    
    <html>
    <head>
    <script type="text/javascript" src="jquery-1.7.js"></script>
    <script type="text/javascript">
    function doSomething() {
        $.get("rss3.php");
        return false;
    }
    </script>
    
    <a href="#" onclick="doSomething();">Click Me!</a>
    
    
    
    </body>
    </html>
    


Comments

  • Registered Users, Registered Users 2 Posts: 11,989 ✭✭✭✭Giblet


    It probably is working, you just don't see the result. You need to wire up a callback for the result
    function doSomething() {
        $.get("rss3.php",function(data){
            alert(data);
        });
        return false;
    }
    
    


  • Closed Accounts Posts: 9,700 ✭✭✭tricky D


    Why use JavaScript? It's bad practice. Just use a submit form function. That's what they're there for.

    <form action="rss3.php" method="post">
    <input type="button" value="Submit" />
    </form>

    more:http://www.w3schools.com/tags/tag_input.asp


  • Registered Users, Registered Users 2 Posts: 131 ✭✭CuAnnan


    tricky D wrote: »
    Why use JavaScript? It's bad practice.
    What?
    tricky D wrote: »
    Just use a submit form function. That's what they're there for.
    They also increase the bandwidth usage on the site by requiring a full reload of the entire site for what could amount to a single piece of data.

    The OP is asking how AJAX works. Telling them that AJAX is bad practice is both patently false and not answering the question. AJAX is an important and the "use a form, that's what they're for" was both patronising and not necessarily true.

    However, to stipulate: AJAX on a live site for the sake of AJAX is bad practice.


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    mach1982 wrote: »
    I playing with some JavaScript.

    I want it to when I click a button that it run a php/perl file .

    I did a bit of googleing :

    http://stackoverflow.com/questions/1280767/how-do-i-run-php-code-when-a-user-clicks-on-a-link

    So I deiced to to test .

    Installed jquery to the same directory as the webpage .

    But it not working , I not a javascript guru, I just playing with it .

    here my code
    &#60;html&#62;
    &#60;head&#62;
    &#60;script type=&#34;text/javascript&#34; src=&#34;jquery-1.7.js&#34;&#62;&#60;/script&#62;
    &#60;script type=&#34;text/javascript&#34;&#62;
    function doSomething() {
        $.get(&#34;rss3.php&#34;);
        return false;
    }
    &#60;/script&#62;
    
    &#60;a href=&#34;#&#34; onclick=&#34;doSomething();&#34;&#62;Click Me!&#60;/a&#62;
    
    
    
    &#60;/body&#62;
    &#60;/html&#62;
    

    The jQuery function you are looking for is .load()

    Just bear in mind that a search engine will never "see" the result, but that would also be the case for a form solution.


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    CuAnnan wrote: »
    tricky D wrote: »
    Why use JavaScript? It's bad practice.
    What?
    tricky D wrote: »
    Just use a submit form function. That's what they're there for.
    They also increase the bandwidth usage on the site by requiring a full reload of the entire sitefor what could amount to a single piece of data.
    .

    Entire page.

    I would use AJAX and JavaScript for user interactions or non-key functions, primarily for the reason that search engines can't access the results.

    It's the same principle as having an alternate text link (where feasible) for general form GET queries - Google can then follow those.


  • Advertisement
  • Closed Accounts Posts: 9,700 ✭✭✭tricky D


    CuAnnan wrote: »
    What?
    Yup, bad practice for accessibility.
    CuAnnan wrote: »
    They also increase the bandwidth usage on the site by requiring a full reload of the entire site for what could amount to a single piece of data.

    The OP is asking how AJAX works. Telling them that AJAX is bad practice is both patently false and not answering the question. AJAX is an important and the "use a form, that's what they're for" was both patronising and not necessarily true.

    However, to stipulate: AJAX on a live site for the sake of AJAX is bad practice.
    Never said AJAX is bad practice, but considering an alternative JS-independent method for reader devices certainly is good practice.


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    tricky D wrote: »
    Never said AJAX is bad practice, but considering an alternative JS-independent method for reader devices certainly is good practice.
    That very much depends on what you are trying to achieve. If you are just trying to add some flare and flashyness to what would otherwise be pretty static content, then yes you really need to consider that. But for modern interactive HTML 5 style applications, alternate JS free methods may be impractical if not impossible.

    Also, while somebody who is just playing around and trying to learn javascript should be mindful of accessibility implications, they don't need to be overly concerned with them, especially not to the point of not using javascript in the first place.


  • Registered Users, Registered Users 2 Posts: 11,989 ✭✭✭✭Giblet


    JavaScript should be absolutely the last thing considered on a page, after everything works. As long as you have good design and html practices, adding the enhanced behaviours should be no problem. And you can be sure your site works without them.


Advertisement