SteveMustafa
SteveMustafa

Reputation: 619

Pass json through click event to jQuery function

I have this old "closed" system where it runs IE in its own container, meaning I have to code like a caveman in many cases because I can't use any browser developer tools/console to x-ray the objects being returned from the remote system.

Now, the specific function I'm looking at is a callback from a third party (it gets complicated) that returns what I am willing to bet is a standard JSON object.

function core_OnUeDeltaItemsUpdate(dataType, oData)
{
    if (dataType == "Units")
    {
        // Bail if dispatch report xml hasn't been loaded yet.
        if (oXml == null)
            return;

        ..... does lots of stuff

        // Reload the content in case any of our displayed units changed
        processUeDelta.click();
    }
}

... at the bottom of the page

<button style="display:none;" type="button" id="processUeDelta"/>

and the attached javascript file that I was hoping would use jQuery

$(function(){
    $("#processUeDelta").click(function(){
        var i = 0;
        alert(this.ueDelta);
        for(var propertyName in this.ueDelta)
        {
            i++;
            alert("property " + i + ": " + oData[propertyName]);
        }
    });
});

Now, currently the last function that binds itself to the hidden button cannot parse oData. I'm stuck on two things here.

  1. I'm not sure how to pass the oData object to the attached eventhandler
  2. I'm not too keen on this design, perhaps there is another way were I can take out the intermediary button so I can then process the JSON data object oData.

Points of note:

Upvotes: 0

Views: 1105

Answers (1)

NaNpx
NaNpx

Reputation: 530

You can replace the core_OnUeDeltaItemsUpdate function with your own and then call the original core_OnUeDeltaItemsUpdate function. In your jQuery file do something like this

$(document).ready(function(){
    window._core_OnUeDeltaItemsUpdate = core_OnUeDeltaItemsUpdate;

    window.core_OnUeDeltaItemsUpdate = function(dataType, oData){

        // pass the parameters into the original function
        _core_OnUeDeltaItemsUpdate(dataType, oData);

        // do whatever you need to do with oData
        var i = 0;
        alert(this.ueDelta);
        for(var propertyName in this.ueDelta)
        {
            i++;
            alert("property " + i + ": " + oData[propertyName]);
        }
    }
});

Upvotes: 1

Related Questions