Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Here's the break down: My problem is two fold, i want to use a button to call to my php script, which in turn calls to my nodejs script running on my little internal test server (this is all done local for now).

Here is my html + script pull:

      <input type="submit" value="Save Sketch" id= "run_system">



  </body>
 <script>
  $('#run_system').on('click', function(){
    $.ajax({
      url : 'exec.php',
      type : "GET"
    }).done(function(data){
      console.log(data);
    });

  });
 </script>

and here is my php script:

 <?php exec('node screenshot.js //place holder url that gets dumped into js file// "); ?>

so my problem is that the previous call to this php is not executing this. Everything i've googled says that this exec("") should run my nodejs script. What am i missing?

I am guessing the type : GET is incorrect, tried not having that line, putting POST in there, nothing seems to work though

Oh one more addition, so when i run the above all it does is print what was in the php file to the console, doesn't actually run the script

share|improve this question
1  
You have one single and one double quote in your exec. –  oyvind 19 hours ago
    
The issue i see here is that your button type is a submit. You would need to prevent that buttons default action by adding event.preventDefault(); after $('#run_system').on('click', function(){ then on your done submit the form –  JD Vangsness 19 hours ago
    
and change $('#run_system').on('click', function(){ to `$('#run_system').on('click', function(event){o –  JD Vangsness 19 hours ago
    
ah that single quote double quote is correct in my actual php file i miswrote it here. My code now reads: <script> $('#run_system').on('click', function(event){ event.preventDefault(); $.ajax({ url : 'exec.php', type : "GET" }).done(function(data){ event.preventDefault(); console.log(data); }); }); </script> however it still isn't downloading a picture –  JumbledOne 19 hours ago

1 Answer 1

up vote 0 down vote accepted

One of the issues is that the exec is executing the command, but you're not capturing / returning the output of that command. You can probably add an echo or print before exec to return the output to the AJAX request.

You might also want to bind to the submit event to handle form submissions as well as submit button clicks, but that would be bound to the form itself.

Ultimately though, I would recommend that you contemplate handling this exec by adding a simple HTTP server to your screenshots.js node script (or something that wraps it) and handle the AJAX request with that. Will likely need to add a Access-Control-Allow-Origin exemption.

share|improve this answer

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.