简体   繁体   中英

Execute second function, Based on the result of First function

data.txt (file)

[{
  "ip": "171.29.39.19",
  "event": "open",
  "marketing_campaign_name": "WEBINAR : Testing Calls Radio",
  "category": ["webinar"]
}][{
  "ip": "66.249.93.80",
  "timestamp": 1509103009,
  "marketing_campaign_id": 1831733,
  "category": ["webinar"]
}]

HTML

<p id="demo"></p>
<script type="text/javascript">    
    $(document).ready(function() {
     $('#demo').load('data.txt') 
    }); 
</script>
<script type="text/javascript">
    function myFunction() {
    var str = document.getElementById("demo").innerHTML; 
    var res = str.replace(/}]/gi, '},').replace(/@##|\[{/gi,'{');
    var output =res.replace(/^,\s*\/?|,\s*\/?$/g,'');
    document.getElementById("demo").innerHTML = output;           
    }; 
</script>

requirement

The result am getting on "onmousemove" function should be obtained without using any Functions like (alert,mouseover etc) ... output should be at oneshot result without any operations.....

HTML 2nd approach

<p id="demo"></p>
<script type="text/javascript">
    $(document).ready(function() {
     $('#demo').load('data.txt')
      alert("data inserted");
    }); 
</script>
<script type="text/javascript">
    $(document).ready(function() {
    var str = document.getElementById("demo").innerHTML; 
    var res = str.replace(/}]/gi, '},').replace(/@##|\[{/gi,'{');
    var output =res.replace(/^,\s*\/?|,\s*\/?$/g,'');
    document.getElementById("demo").innerHTML = output;           
    }); 
</script>

requirement

The result am getting after accepting alert at output should be obtained without using any Functions like (alert,mouseover etc) ... output should be at oneshot result without any operations.....

(ps:i guess it need some time after first script execution,cuz the second script is relayed on first script)

Thanks a lot in advance.....

Simply call myFunction after loading the text file, by passing it as a callback to .load() :

$(document).ready(function() {
    $('#demo').load('data.txt', myFunction) // Pass it here as a callback
}); 

function myFunction(theText) {
       // Here do what you want with theText
};

http://api.jquery.com/load/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM