Fizzy
Fizzy

Reputation: 21

Javascript Grab a value from another page

I am trying to make a JavaScript that will grab a text value from another page, and set it as a value in the script to be used later on.

Basically the value is named 'country' in the script, and is under the td id of country on the page I am attempting to grab it from. As the code currently stands, it just returns blank.
If anyone has any suggestions to make this work, or maybe just a completely different method much would be appreciated.

function loadCountry() {
  $("#countryget").load('https://domain.com/client/12345' + ' #country', function(){
  country = $('#countryget #country').text();
 })
//loadCountry()
}

alert(loadCountry())

Upvotes: 2

Views: 112

Answers (1)

gstroup
gstroup

Reputation: 1064

I think it would be easier to store the 'country' data as an array in a javascript file. This script file could be shared by separate pages on your site, and you can populate your UI easily with jquery. If you really want to rewrite everything, then a single page app would solve this problem too.

Upvotes: 1

Related Questions