I am trying开发者_开发知识库 to use Jquery's .get
function (below) to return a simple text value, either 0 or 1 and turn that value into a variable. Here's what I am trying
jQuery.get( url, [data,] [success(data, textStatus, jqXHR),] [dataType] )
with my url being myexternalsite.com/text.txt
can i use a text file to simply return either a 0 or 1 and how do I make this a variable?
Well if you're running a callback function. just use the "data" of your callback function and set the variable you want e.g. myvariable = data
yes you can use anything you want.
var myVariable;
$.get(url,function(data){
myVariable = data;
alert('the variable has been initialised');
});
Ajax calls are restricted to the same domain, so an ajax call to an external site ("myexternalsite.com") is forbidden. For that you should use a proxy; this way, your url variable would be something like url = 'myProxy.php?url=myexternalsite.com/text.txt'
精彩评论