0

In the android phonegap application i need to get the script of index2.html from index1.html using javascript or jquery.

Here is index1.html code:

   function nextpage(){

   $.get('index2.html', function(data) {
          $('#div').html(data);
          alert('Load was performed.');
        });
     }

      <input type="button" value="button1" onclick="nextpage()"/> 
      <div id="div"></div>

Here is index2.html code:

function return1()
     {
 alert("welcome to index2.html");
 var data={ "firstName": "John", "lastName": "Doe", "age": 25 };
     }

     <input type="button" value="welcome" onclick="return1()"/> 

From this code i am getting the 'welcome' button from index2.html and appended in #div of index1.html.But i need to append the return1() in #div and need to get the alert("welcome to index2.html").That is html page function response.How to do this.Please help me.Thanks in advance.

JavaH
  • 427
  • 2
  • 11
  • 29

1 Answers1

0

i am adding return1() function in your code after appending index2.html.

function nextpage(){

   $.get('index2.html', function(data) {
          $('#div').html(data);
          alert('Load was performed.');

              return1(); //call this function to show alert

        });
     }
Roopchand
  • 2,608
  • 2
  • 17
  • 20
  • Ok Thanks.I need to read only json from index2.html.How to do it.I dont want full html page.Please guide me.Please see the Edit in index2.html code above. – JavaH Oct 06 '12 at 13:59
  • if you want json data from other file,better to use one php file which generate json data,use this json file url in your main page and decode json and use it,no need to append file like as you are doing,.....if you are doing this one in phone-Gap then put your php file on server then use server url in java-script or you can use directly json formatted file in your phone-gap folder,read this file with javascript. – Roopchand Oct 08 '12 at 04:59
  • Thanks Roopchand.But i should not use php.Only javascript and jquery.Please can you provide any other solution. – JavaH Oct 08 '12 at 06:42
  • ya that's why i already wrote you can use json file directly like "data.json" in your folder after that you can fetch data from this file through java-script/jquery. – Roopchand Oct 08 '12 at 08:48
  • $.getJSON(json_file_URL, function(data) { var json_data = data.item; $('#div_id').text(json_data.firstName); }); – Roopchand Oct 08 '12 at 08:58
  • I have tried this code in index1.html. Instead of json_file_URL i used index2.html, but i didnt get any alert inside the getJSON. Please help me. – JavaH Oct 09 '12 at 04:49
  • why you want to add alert function from other file,you just can add in your main file add call alert function when you successfully fetch and append second file json data,check condition if append success alert function. – Roopchand Oct 09 '12 at 06:29
  • But $.getJSON is not called.To test that i used alert inside $.getJSON("index2.html", function(data) { alert(data);$('#div_id').text(json_data.firstName); });.I didnt get alert(data);.Please help me. – JavaH Oct 09 '12 at 06:57