Pass json through click event to jQuery function

1.1k Views Asked by At

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:

  • This is based on a data pump, so this callback is being called on an average of 5s.
  • I am limited to using jQuery 1.7.1
  • I cannot see the object, my browser cannot act as a test harness, there are too many moving parts for me to be able to test it from outside the application.
1

There are 1 best solutions below

0
NaNpx On

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]);
        }
    }
});