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

  • SEARCH
  • Home
  • 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 8712581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:08:26+00:00 2026-06-13T05:08:26+00:00

I have the below function defined that passes a dynamic id to the function

  • 0

I have the below function defined that passes a dynamic id to the function as a parameter and output to an html link. The script it calls updates a database record and returns an alert of success or failure based on query being successful, or the id failing some validation.

     function cancel_file(id){  
            jQuery.ajax({
            type: "POST",
            url: "https://www.mysite.com/cancel.php",
            data: 'id='+ id,
            cache: false,
            success: function(response){
                console.log(response);

                if(response == 1){
                    alert('File successfully cancelled!');
                    }
                }
            error: function(response){
                console.log(response);

                if(response == "invalid_id"){
                    alert('The file ID format is invalid');
                }else if(response == "no_record_found"){
                    alert('No file found with ID specified');
                }

            }
        });
    }

And I am calling it in the section of my document as follows

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="/js/jquery.js"></script>

The link on the page is output using the following php code

<?php echo "<a href='#' onclick='cancel_file(".$id.")'>Cancel </a>"; ?>

When the link is clicked nothing happens and when I examine the Chrome JS Debugger Console it shows “Uncaught ReferenceError: cancel_file is not defined”. I did some reading that functions defined within the document.ready() are ignored by Chrome and FF so I removed that declaration from the top. I am still new to jQuery so any help is greatly appreciated.

TIA

cancel.php

<?php

// Get the fileid and make sure it's in a valid format
    $id = $_POST['id'];

    if(!ctype_digit($id)){
        $response = "invalid_id";
    }else{
        // If validation passes proceed to queries and cancellation process
            $q1 = "UPDATE `table_files` SET `is_invalid` = 1 WHERE `id` = '".$id."'";
            $r1 = mysql_query($q1) or die(mysql_error());

        if(mysql_affected_rows() > 0){
            $response = mysql_affected_rows();
        }else{
            $response = "no_record_found";
    }

    echo $response;
?>

$response is what should be passed back to the jQuery function.

  • 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-13T05:08:27+00:00Added an answer on June 13, 2026 at 5:08 am

    I found a workaround by loading the PHP script into a jQuery UI modal and processed it there. Not exactly what I was hoping but it does the trick nicely.

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

Sidebar

Related Questions

I have template function compare defined as below. #include<iostream> using namespace std; template<typename T>
I have the following function below: public function setupHead($title){ $displayHead .='<!DOCTYPE html PUBLIC -//W3C//DTD
I have an example function below that reads in a date as a string
I have created a function (see below) that calculates a 7.5% sales tax. Now
Hi I have written below code function unique(th){ var obj = {}; for(var i
let say i have function like below function doSomethingNow(){ callSomethingInFutureNotExistNow(); } at the moment
I have the function below. It gets the values from checked boxes and transfer
I have written a function below: void trans(double x,double y,double theta,double m,double n) {
I have the below prog Object.prototype.inherit = function(baseConstructor) { this.prototype = (baseConstructor.prototype); this.prototype.constructor =
I have the below configuration where I'm trying to create a test C function

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.