Page 1 of 1

ajax url

Posted: Fri Mar 14, 2014 10:27 am
by bsinclair
I am have an ajax command in my java script and it works great with all hard coded values. How do it get it to work with a variable value? I have tried create the URL as a variable and entering ajax(variable) which included the complete URL


This works:
var responseText = ajax("http://as400.bass-net.com:10088/testbs/ ... ewcont=109");


This does not work:
var container = 109
var myajax = '"http://as400.bass-net.com:10088/testbs/ ... p?newcont=' + container + '"';
var responseText = ajax(myajax);


Thanks
bill

Re: ajax url

Posted: Fri Mar 14, 2014 11:21 am
by kai.barrus
I think your issue may be in how you're building the myajax URL. The following works for me (same request sent, same response):

Code: Select all

var responseText = ajax("http://md5.jsontest.com/?text=109");
console.log(responseText);

var to_md5 = 109;
var ajax_url = "http://md5.jsontest.com/?text=" + to_md5;
var responseText2 = ajax(ajax_url);
console.log(responseText2);
You don't need to have quotes around the whole URL string. By adding the extra quotes the browser is probably trying to send the ajax request to that resource on the current path (when I try, the ajax request tries to go to http://<my IBM i>/%22http://md5.jsontest.com/?text=109%22 -- the " characters get url encoded to %22).

Re: ajax url

Posted: Fri Mar 14, 2014 11:42 am
by bsinclair
thanks again for your help