-4

I have this button called save button. On clicking on it, I want it to call a PHP file on the server which will then let user download a text file with some data.

This is my button code

<img id="save" class="normal_button"  src="buttons/save.png">

This is my jQuery file

jQuery(document).ready(function(){
    jQuery("#save").click(function(){
        jQuery.get("download.php"); 
    });     

Here is my php file named download.php

<?php
    echo "connected";
?>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
knight
  • 1
  • 4
    The jQuery documentation works wonders with this kind of quesions: https://api.jquery.com/jquery.get/ – Amarnasan Sep 07 '15 at 07:38
  • 1
    Is the file static or you need to dynamically retrieve and download the file? – Rafael Sep 07 '15 at 07:43
  • Separately, please take the [tour](http://stackoverflow.com/tour), have a look around, and read through the [help center](http://stackoverflow.com/help), in particular [*How do I ask a good question*](http://stackoverflow.com/help/how-to-ask)? – rrk Sep 07 '15 at 16:58
  • `$.get("downlaod.php", function (data) { alert(data); }).fail(function () { alert("error"); }); ` try this. If error alert is coming, that means something is wrong with either `download.php` or the way it is called, may be the path is wrong. – rrk Sep 08 '15 at 02:24

1 Answers1

1
  $(document).ready(function(){
    $("button").click(function(){
        $.get("download.php", function(data, status){
            alert("Data: " + data + "\nStatus: " + status);
        });
    });
});
worlock
  • 190
  • 1
  • 18