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 7770773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:29:26+00:00 2026-06-01T16:29:26+00:00

I am currently using the JQuery ajax function to call an exterior PHP file,

  • 0

I am currently using the JQuery ajax function to call an exterior PHP file, in which I select and add data in a database. Once this is done, I run a success function in JavaScript. What’s weird is that the database is updating successfully when ajax is called, however the success function is not running. Here is my code:

<!DOCTYPE html>
<head>
<script type="text/javascript" src="jquery-1.6.4.js"></script>
</head>
<body>
<div onclick="addtask();" style="width:400px; height:200px; background:#000000;"></div>
<script>
function addtask() {
var tid = (Math.floor(Math.random() * 3)) + 1;
var tsk = (Math.floor(Math.random() * 10)) + 1;

if(tsk !== 1) {
    $.ajax({
    type: "POST",
    url: "taskcheck.php",
    dataType: "json",
    data: {taskid:tid},
    success: function(task) {alert(task.name);}
    });
}
}

</script>
</body>
</html>

And the PHP file:

session_start(); 

$connect = mysql_connect('x', 'x', 'x') or die('Not Connecting'); 
mysql_select_db('x') or die ('No Database Selected'); 

$task = $_REQUEST['taskid']; 
$uid = $_SESSION['user_id']; 

$q = "SELECT task_id, taskname FROM tasks WHERE task_id=" .$task. " LIMIT 1"; 
$gettask = mysql_fetch_assoc(mysql_query($q)); 

$q = "INSERT INTO user_tasks (ut_id, user_id, task_id, taskstatus, taskactive) VALUES (null, " .$uid. ", '{$gettask['task_id']}', 0, 1)"; 
$puttask = mysql_fetch_assoc(mysql_query($q)); 

$json = array( 
    "name" => $gettask['taskname'] 
); 

$output = json_encode($json); 
echo $output; 

Let me know if you have any questions or comments, thanks.

enter image description here

  • 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-01T16:29:27+00:00Added an answer on June 1, 2026 at 4:29 pm

    Ibelieve it runs but alert wont show because of error –

    success: function(task) {alert(task.name);} 
    

    You have to decode JSON first with jQuery.parseJSON(), task is just a string
    it shoudld look somthing like this

    function(m)
            {
                var task = jQuery.parseJSON( m );
                alert(task['name']);
            }
    

    Edit:
    Ok …
    Try to use developer tools in your browser and place breakpoint on your success function, if it doesnt even lunch try to add error callback for your ajax call

    error: function(xhr, exc)
    {
       alert(xhr.status);
       alert(exc);
    }
    

    Edit2:
    and there is your problem – your ajax is not only returning json data, but php warning too, and now I see where is your problem – you are fetching data after insert, delete

    $puttask = mysql_fetch_assoc(mysql_query($q));
    

    Now I feel bad for not noticing it sooner…

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

Sidebar

Related Questions

I'm using the JQuery AJAX function to deliver data to a PHP doc. Currently,
I'm currently using jquery ajax to call a pagemethod (which works great); $.ajax({ type:
I'm currently using jquery's ajax feature or whatever they call it. To load data
I'm currently new into client-side programming, especially using the Jquery Ajax method to call
I'm using JQuery to call a PHP function that returns a JSON string upon
I am currently using JQuery Ajax to retrieve and display some data as follows.
I'm currently using jQuery Cookies plugin, and depending on which side of the page
I am currently using jQuery to load a variable php layout depending on the
I am currently using Valums JQuery File Upload plugin. The plugin is very convenient
I have a jquery Ajax call function that I use to submit form to

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.