0
I tried to create a small function:
$(document).ready(function(){
var value0;
$.get( "file.php?id=1", function(data){
value0 = data;
});
arrayAmount[0]=value0;
var value1;
$.get( "file.php?id=2", function(data){
value1 = data;
});
arrayAmount[1]=value1;
var value2;
$.get( "file.php?id=3", function(data){
value2 = data;
});
arrayAmount[2]=value2;
}
function buyVps(){
var vpsDetails='Processor : '+arrayProcessor[sliderValue]+' GHZ'+'\nRAM : '+arrayRam[sliderValue]+' MB'+'\nRAID Storage : '+arrayStorage[sliderValue]+' GB'+'\nMySql Databases : '+arrayMySqlDB[sliderValue]+' GB'+'\nMonthly Price : '+'R$ '+arrayAmount[sliderValue];window.open(arrayLink[arrayBlocks[sliderValue]], '_blank');
};
I need it to take the value that is returned when the URL is accessed. It is not in JSON, it returns in plain text, only a value like for example: 79.90
I need it that way, using the arrayAmount[0]=
, because it is part of another function.
How should I adjust the script?
If it is to return a simple text as you said, pq then is passing parameters in the url, id and periodicity?
– LeAndrade
These parameters are to return the correct plan value, each plane has a different ID. The return is only text.
– Wendler
If you give a
console.log(data);
you return what?– LeAndrade
@sam... Yeah, I noticed he always returns Undefined, not the value.
– Wendler
Hmm, I don’t really know how it should be done... if you can show me some tutorial where I can better inform myself I appreciate.
– Wendler
I updated the question with the rest of the function.
– Wendler
This url you search for your plain text is an API?
– Pedro Paulo
The bid is to use the variable inside Ajax: https://jsfiddle.net/Lsf8d5u4/2/
– Sam
@sam... The problem is that there are several arrayAmount:
arrayAmount[0],arrayAmount[1],arrayAmount[2]
and each with different parameters in the URL, so there would be no way I could put directly in the function that prints the value in HTML.– Wendler
@Pedropaulo... yes
– Wendler
But then you play as a function parameter whatever is different. Well at first this is it, Ajax will fetch on another page the information, and this can take from fractions of seconds to a few seconds, so you have to build the code that fits into this.
– Sam
@sam... I did a test using your tip, continued giving Undefined.
– Wendler
The
data
only has value inside the Ajax callback. Outside is Undefined.– Sam