-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";
?>
4
  • 4
    The jQuery documentation works wonders with this kind of quesions: api.jquery.com/jquery.get Commented Sep 7, 2015 at 7:38
  • 1
    Is the file static or you need to dynamically retrieve and download the file? Commented Sep 7, 2015 at 7:43
  • Separately, please take the tour, have a look around, and read through the help center, in particular How do I ask a good question? Commented Sep 7, 2015 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. Commented Sep 8, 2015 at 2:24

1 Answer 1

1
  $(document).ready(function(){
    $("button").click(function(){
        $.get("download.php", function(data, status){
            alert("Data: " + data + "\nStatus: " + status);
        });
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

refrence: - w3schools.com/jquery/ajax_get.asp good luck!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.