0

Hi there guys having some problems with a script

I have some tab fields that load a html url

I need to get the parameters of that url in the html that i loaded

<div id="tabs">
<ul>
    <li><a href="hosts/timeline.html?ip=${ipValue}">Timeline</a></li>
</ul>

this is my timeline.html file content

<script id="timelineTmpl" type="text/x-jquery-tmpl"> 

{{each response}}
    <li><b>${time}</b><br />
    {{each items}}
            ${icon}: <em>${text}. </em> <br />
    {{/each}}   
{{/each}}

</li>
</script>

<ul id="timeline"></ul>


<script type="text/javascript" charset="utf-8">

    function getURLParam(urlSearch, param) {
        p = urlSearch.split(/[&?]/);
        p = _.reject(p, function(e) { return e == "" });
        p = _.map(p, function(e) { return e.split("=")});   
        p = _.reduce(p, function(memo, a) {memo[a[0]] = a[1]; return memo; }, {});
        return p[param]
    }

    var request = $.ajax({
        type: 'GET',
        url: 'ajax/hosts/timeline.xsp?ip='+getURLParam(location.search, "ip"),
        dataType: 'json'
    });

    request.done(function(data){
        $("#timelineTmpl").tmpl(data).appendTo("#timeline");
    });

    request.fail(function(jqXHR, textStatus, errorThrown) {
        console.log(errorThrown);
        console.log(textStatus)
    });

Now that function getURLParam returns undefined

how can I get it to retrieve that ip vale that i have passed

Ok, Could it be the way that I request the timeline.html ?

Ancyent
  • 27
  • 1
  • 8

2 Answers2

2

I have the very same problem. The link provided does not answer your question either. I couldn't solve it so i used a workaround that may help you. Just append the data to any DOM element.

For example, in your template document:

$(document).ready(function() {
    $('#tabs').data('ip', '${ipValue}');
});

Then, in your timeline.html you could do:

 url: 'ajax/hosts/timeline.xsp?ip=' + $('#tabs').data('ip')

Hope it helps,

metacortechs
  • 141
  • 1
  • 1
  • 6
0

First of all, I would change this hosts/timeline.html into hosts/timeline.php; I dont think that HTML knows how to work with parameters passed that way; and then retry; and be carefull where you use the RegEx, you should use split(/[&?]+/) because you could have multiple params and values

Ionut Flavius Pogacian
  • 4,750
  • 14
  • 58
  • 100
  • I have give the files and extensions because i cannot use anything else. as for regex no worries ... that function can be removed if you know another way :) – Ancyent Jun 14 '12 at 09:43