Q.js file
Q = {};
Q.stringFile = [];
Q.file = "CSS.txt";
Q.getData = function(Q.file){
$.get(Q.file, function(data){
var str = data;
Q.stringFile = str.split("\n");
return Q.stringFile;
});
}
a.html file
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="Q.js"></script>
<script type="text/javascript">
var d = Q.getData(Q.file);
alert(d);
</script>
</head>
<body>
</body>
</html>
alert doesn’t output!
Errors: Q is not defined ;
unexpected token .
How do i fix this??
As I said in my comment, you cannot return data from an Ajax call, as the Ajax call is asynchronous. You have to make your function accept a callback, like:
and then call it with:
Regarding the errors: You have a syntax error in this line
Q.fileis not valid here. The browser cannot parse and process the file and soQwill not be defined.I have the impression, you should first read some tutorial before you go on.