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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:22:41+00:00 2026-06-13T00:22:41+00:00

I have the following jQuery AJAX to duplicate a background image. I am stumped

  • 0

I have the following jQuery AJAX to duplicate a background image. I am stumped as to how to effectively return information back to the original page. Here is the AJAX I send on click of “‘#dupBtn”…

//DUPLICATE BACKGROUND      
$('#dupBtn').click(function() {
    jQuery.ajax({
            type: "POST",
            dataType:'json',
            url: "../system/bgUpdate.php",
            data: {
                "user":<?= $_POST['user'] ?>,
                "bgID":bgID,
                "refID2":<?= $_POST['refID2'] ?>,
                "refTable":"<?= $_POST['refTable'] ?>",
                "bgTitle":($('#bgTitle').val()),
                "path":path,
                "bgColor":bgColor,
                "bgPoz":bgPoz,
                "bgRepeat":bgRepeat,
                "attach":attach
                }
        });
});

Here is the basic MySQL query on the PHP page bgUpdate.php.

mysql_query("INSERT INTO backgrounds (user,title,path,bgColor,bgPosition,bgRepeat,bgAttachment) VALUES ('".$_POST['user']."','$title','".$_POST['path']."','$bgColor','".$_POST['bgPoz']."','$rt','$attach')");

$bgIDnew = mysql_insert_id();

What I want to do is have the following code fired on the original page upon successful execution of the MySQL entry, dynamically catching the ‘$bgIDnew’ from the MySQL PHP page.

$('#bgPickerBox').load('../dialog/bgPickerAlbums.php?album=<?=$bgIDnew?>');
  • 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-13T00:22:43+00:00Added an answer on June 13, 2026 at 12:22 am

    You can accomplish this with the success attribute of the .ajax() function:

    $('#dupBtn').click(function() {
        jQuery.ajax({
            type: "POST",
            dataType:'json',
            url: "../system/bgUpdate.php",
            data: {
                ...
                },
            success:
                function(response)
                {
                    $('#bgPickerBox').load('../dialog/bgPickerAlbums.php?album=<?=$bgIDnew?>');
                }
        });
    });
    

    That’s only part of it though… The other half is that your PHP needs to return something that jQuery can understand as a “successful” call. My preference is to use HTTP status codes. In your case, your PHP script should return a 200 code if it was successful; otherwise, it should return something in the 400 range. (By the way, if you want jQuery to do something separate with errors, you can use the error property of .ajax().)

    However, if you need to return data from the server to the client-side script, then your PHP can print out that information like this:

    mysql_query("INSERT INTO backgrounds (user,title,path,bgColor,bgPosition,bgRepeat,bgAttachment) VALUES ('".$_POST['user']."','$title','".$_POST['path']."','$bgColor','".$_POST['bgPoz']."','$rt','$attach')");
    
    $bgIDnew = mysql_insert_id();
    // Best practice to keep it in some sort of understandable format
    // Here, we'll put it in an associative array:
    $response = array('id' => $bgIDnew);
    print_r(json_encode($response));
    

    This PHP script sends back to the ajax() method a JSON representation of the $response variable. You’ve already configured that ajax() method to read the response dataType as JSON, so it already knows how to read the response parameter… Which means your success function can look something like this:

    success:
        function(response)
        {
            $('#bgPickerBox').load('../dialog/bgPickerAlbums.php?album=' + response.id);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: jquery ajax return: undefined I have written the following code to check
Possible Duplicate: jQuery: Return data after ajax call success I have the following function
i have the following references to jquery on my page: <link href=http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css rel=stylesheet type=text/css/>
I have the following .htaccess RewriteRule ^register.html$ ?page=register I have a jquery ajax function
I have the following jQuery $.ajax({ type: GET, url: http://f.cl.ly/items/0i1V1L1k2F440L1m2Y0G/pointdata.xml, dataType: xml, success: parseXml
I have the following simple jquery snippet $(document).ready(function () { $.ajax({ url:myjson.json, dataType: 'json',
Hi I have the following code with jQuery: function reject(id) { $.ajax({ type: 'POST',
I have the following Javascript libraries loaded for my page. <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js></script> <script
I have the following jquery code: $(document).ready(function() { $(body[class*=page-calendar-practices] #content-header h1#title).after(<div id='athletics_practice-schedule'><div id='inner-title'><a href='www.example.com'
I have the following JQuery AJAX call that sends HTML form data to my

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.