Powered by Blogger.

PASSING VARIABLES BETWEEN FUNCTIONS IN AJAX CALLBACKS


Passing a variable from one ajax response into URL of another ajax call
$.ajax({
type: "POST",
 url: "Dictionary.txt",
 dataType : "text",
 success: function (data) {
 wordslist = data.toString().split("\n");
 randomLineIndex = Math.floor( Math.random() * wordslist.length );
 word = wordslist[randomLineIndex];
 xmldatalist();
 },
 error: function (error) {
 alert("Error : "+error);
 console.log(error);
 }
 });
 function xmldatalist() {
$.ajax({
type: "POST",
 url: 'http://localhost:8888/proxy/http://[your destination.com]/?w='+word+'&xml=1',
 dataType : "xml",
 success: function (data) {
 console.log(data);
 },
 error: function (error) {
 alert("Error : "+error);
 }
 });
 }

No comments