Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to make Ajax start a daemon on the server with the following JQuery code. The alert pops up but the daemon doesn't start. What is the proper way to format the section that is $.ajax({data: {},; to make this code work. I have been searching for hours for an example related directly to this but came up only with broad scoped and convoluted piles of generally stinky poopoo-lery:) Thanks.

UPDATE

I am still unable to launch the daemon. I have added a php file on the server as recommended which is called "executedp.php". It contains a script I hoped would accomplish the task. However, it has not.

Does anyone see what I am missing.

Here is the php code for executedp.php:

<?php $startDaemon = exec('sh ~/.devilspie/ruleset.sh $x; done'); ?>

Here is the updated JQuery code:

        if(found) {
        var xhr = $.ajax({ 
        url: 'executedg.php',
        success: alert("It has begun!")  
        }); 

        switch($.tableCount) {

        case ($.tableCount = 1):
        window.open('table1.html');
        xhr;
        break;          

        case ($.tableCount = 2):
        window.open('table1.html');
        window.open('table2.html');
        xhr;
        break;

        case ($.tableCount = 3):
        window.open('table1.html');
        window.open('table2.html');
        window.open('table3.html');
        xhr;
        break;

        case ($.tableCount = 4):
        window.open('table1.html');
        window.open('table2.html');
        window.open('table3.html');
        window.open('table4.html');
        xhr;
        break;
        }
        }
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

When you invoke the XmlHttpRequest (xhr), you must indicate an URL / URI to be executed on the remote server. In the script contained in this URI is where you have to start your daemon.

You need something more apart from just client side coding (Jquery), but also some server side scripting.

EDITED: I think you are messing the old school XmlHttpRequest and $.ajax. The code you have only makes the ajax request on the first invocation, when you define xhr. When you reference the xhr object again, inside the switch command, the ajax call is not being fired.

share|improve this answer
    
Ok, I created executedg.php on the server which contains: code$startDaemon = /home/dealer/gdevilspie-0.31/gdevilspie; $x; done;codeand added url: 'executedg.php' to the ajax code but still not clear on how to call it from the ajax script. –  Larry Feb 21 '12 at 19:21
    
I think it is enough with: $.ajax({url: 'executedg.php'}); More information here: api.jquery.com/jQuery.ajax –  jap1968 Feb 21 '12 at 19:36
    
Sorry about the code tags in the reply, not sure how to do it. @jap1968 –  Larry Feb 21 '12 at 19:37
    
Same problem here! –  jap1968 Feb 21 '12 at 19:38
    
Still no luck. I have updated the code with what I have done so far. @jap1968 –  Larry Feb 21 '12 at 21:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.