Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8194067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:41:43+00:00 2026-06-07T04:41:43+00:00

I am trying to call a PHP function using AJAX. Below is the script

  • 0

I am trying to call a PHP function using AJAX. Below is the script I used.

<script type="text/javascript" src="jquery.1.4.2.js">

    $(document).ready(function () { 

               // after EDIT according to 
               // @thecodeparadox answer

       $('#local').click(function(e){
            e.preventDefault();
            e.stopPropagation();
            promptdownload();
       });
    });

        function promptdownload(e) 
        {
        $.ajax({
             type: "POST",
             url: "js/prompt.php",
             data: { "get" : "runfunction", "action" : "promptlocal" },
             success: function (response) {
             }    
         });
        }
</script>

The corresponding PHP code (prompt.php) is:

<?php
$path1 = "downloads/1.jpg";
$browserFilename1 = "Local Travel";
$mimeType1 = "image/jpeg";


function promptToDownload($path, $browserFilename, $mimeType)
{

    if (!file_exists($path) || !is_readable($path)) {

        return null;
    }

    header("Content-Type: " . $mimeType);
    header("Content-Disposition: attachment; filename=\"$browserFilename\"");
    header('Expires: ' . gmdate('D, d M Y H:i:s', gmmktime() - 3600) . ' GMT');
    header("Content-Length: " . filesize($path));
    // If you wish you can add some code here to track or log the download

    // Special headers for IE 6
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    $fp = fopen($path, "r");
    fpassthru($fp);
}

if ($_POST["action"] = 'promptlocal')
{
    promptToDownload($_GET[$path1], $browserFilename1, $mimeType1);//comments
}

?>

This is how I code the button that is supposed to trigger the function:

<input type="button" id="local" name="local" value="Local Travel">

My expected output is to have this button promt the user: “where to save 1.jpg file”.

However I couldn’t make it work.

Any advise is highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:41:44+00:00Added an answer on June 7, 2026 at 4:41 am
    $('local').click(function(e){
    

    should be

    $('#local').click(function(e){
    

    As local is an id so you should use # before it. And also in your php code there are some missing quotes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to pass PHP Function parameters using Javascript (not JQuery) AJAX. Do I
I'm trying to call to external PHP script using Ajax like this: $(function() {
Is it possible to call a php class function DIRECTLY using ajax? Something like
This is a part of the code in a 'process.php' file: echo <script type='text/javascript'>
I am trying to make an ajax call to a php script. The php
I'm using a jQuery ajax json call to retrieve a 3 dimensional PHP array
I am trying to pass a dataString to to an ajax call using JQuery.
I'm trying to renew my company intranet using jquery, ajax and php. General aspect
I am trying to get a Ajax-call made from jQuery to return a JavaScript
i'm making an ajax call to a php function... i'm trying to display the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.