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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:06:35+00:00 2026-06-07T15:06:35+00:00

I’m currently working on a PhoneGap application that uses jQuery, jQuery mobile and a

  • 0

I’m currently working on a PhoneGap application that uses jQuery, jQuery mobile and a lot of XML. This has been handed to me as the guy who started working on this isn’t around anymore (but I won’t go into that). Okay, an overview… I have a page that reads from an XML file and then uses the returned data to inject images and information of available products. When the user clicks on one of these images I wish to display a dialog… this is easy I just use the following (the dialog is a div within my page not a separate file)

$('#entry_level_phones img').live("click", function(){
    $.mobile.changePage("#popupEntry", { role: "dialog"});    
});

Okay, I now wish to extend this so when a specific image is clicked I read the same XML file and retrieve more information on the chosen product. This information is formatted, injected as innerHTML into the dialog div and displayed… something like so…

$('#entry_level_phones img').live("click", function(){
    // I know the ID of what was clicked using this.id!
    $.ajax({
        type : 'GET',
        url : 'hardware.xml',
        dataType : 'xml',
        success : getProduct(this.id)
    });
});

function getProduct(productID){

    productContent = "";
    // code to parse through XML and format using the passed productID to locate the relevent info 
    productContent = outFromParsingData;
    $("#popupEntry").html(productContent); 
    $.mobile.changePage("#popupEntry", { role: "dialog", "test":"test" });    
}

now the problem is I need to pass the relevant id (this.id) to the success callback. Normally you would just state the function name and the returned xml from the ajax call is passed through (I still don’t understand how and why).

success : getProduct // this is ajax call

getProduct(xml) // here's the returned xml passed as an argument 

with the amends above I can read the returned XML but I don’t have my chosen ID… so finally my question… how do I pass the id and xml to my getProduct function? Many thanks.

  • 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-07T15:06:37+00:00Added an answer on June 7, 2026 at 3:06 pm

    Your approach of reloading the same XML each time the image is clicked sounds pretty inefficient to me. If you’ve already loaded the XML to create your images and the related content, would it not make more sense either to store the relevant information associated with each image on the element itself using a data attribute, or store the XML data in a variable and look up the relevant entry with the ID when the image is clicked?

    But to answer your question, if you define the handler within the request you can use a closure and variables declared within the scope of your click handler will be available within the scope of the AJAX handler:

    $('#entry_level_phones img').live("click", function() {
        var $this = $(this);     
        $.ajax({
            type : 'GET',
            url : 'hardware.xml',
            dataType : 'xml',
            success : function(data) {
                 // $this should be within scope here
                 console.log($this);
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.