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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:46:07+00:00 2026-05-28T01:46:07+00:00

I am having a little difficulty. Basically I am sending information from a form

  • 0

I am having a little difficulty. Basically I am sending information from a form via jQuery and AJAX to MySQL, then returning a value back to my application.

I am able to add the information to my DB but I cant seem to work out how to retrieve the ID of the data inserted. Here is my code –

function submitDeliveryDetails(){
    $.ajax({                       
        url: "http://www.mydomain.co.uk/mobileapp/add_deliverydetails.php?callback=jsonp1",
        data: addDeliveryData, // Variable holding said delivery information
        jsonp: "callback",
        dataType: "jsonp",
        success: function(data) {
            $.each(data, function(index) {
                alert(data[index].orderId);
            });                       
        },                     
        error: function(){                       
            //Do Stuff                       
        }
    })
}

This sends the information fine. I am able to add to the DB and using the following to return the ID

$orderId = mysql_insert_id();

I then create JSON format for this value,

$orderIdArray = array('orderId'=>$orderId);
echo $_GET['callback'].'('.json_encode($orderIdArray).')';

When I view this in FireBug, I can see the ID, What I need guidance is how to handle this ID to get it back into my application, As I am getting ‘undefined’ doing things my way!

Thanks
Rory

p.s. I am using JSONP as I am dealing with scripts on a separate domain.

Plain text JSON –

({"orderId":125})
  • 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-05-28T01:46:08+00:00Added an answer on May 28, 2026 at 1:46 am

    The ajax call is asynchronous. That means the ajax call completes and the following functions in your code continue to execute while the ajax call is underway and before it completes. Therefore, the ONLY place you can do anything with the return value is in the success handler for the ajax function or in any functions you call from there.

    This requires changing the flow of your coding, but you need to make the ajax call and then continue the flow of execution in the success handler once the ajax call successfully completes.

    Conceptually, it’s like this:

    function submitDeliveryDetails(){
        $.ajax({                       
            url: "http://www.mydomain.co.uk/mobileapp/add_deliverydetails.php?callback=jsonp1",
            data: addDeliveryData, // Variable holding said delivery information
            jsonp: "callback",
            dataType: "jsonp",
            success: function(data) {
                $.each(data, function(index) {
                    alert(data[index].orderId);
                });                       
                // you can now continue on here with whatever you wanted to do 
                //    with the the returned JSON data
                // You can operate on the data here or call other functions 
                //    (passing the data as an argument to those functions)
            },                     
            error: function(){                       
                //Do Stuff                       
            }
        })
    }
    
    submitDeliveryDetails();
    // nothing else to do here because the ajax call has not completed yet
    // so the returned results from the ajax call is not available yet
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a little difficulty with a generic template for my extended progress
Forgive me if this is a tried question, but I'm having a little difficulty
I'm having a little bit of trouble making a sticky form that will remember
I am having a little difficulty working with states in Flex (or Flash) 4.
I am having a little bit of difficulty passing a variable into a selector
Hi i am having a little trouble with my jquery tabs, for some reason
I'm having difficulty extracting amplitude data from linear PCM on the iPhone stored in
I'm having a little difficulty getting the icon image to align properly in my
im having a little difficulty in making a regex that will filter an input
I am having a little difficulty with the below code - it return 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.