views:

50

answers:

2

Hi,

I am trying to send a date to the server as part of a get transaction, however, looking at the urls (through firebug), it appears that the var sDate is never replaced with its value.

Sorry i'm very new to JS and Jquery, so this is likely a very elementary mistake - i'm guessing it has something to do with the map that i am trying to pass to $.get?

function drawVisualization(sDate, eDate) {

alert(sDate + eDate);    

$.get(
      "http://localhost:8080/",
      "{'start':sDate}",
      function(data) { alert(data); },
      "html"
 );

update : To me the most likely candidate seemed the "" around the mapped date variable - but removing these makes the url default to just http://localhost:8080/ - with no additional data payload. I got the form for the GET request from here btw.

update 2 :
Thanks to pointers here and some more googling, I managed to get the following working:

$.get(
        "http://localhost:8080/",
        {'start':JSON.stringify(sDate), 'stop':JSON.stringify(eDate)},
        function(data) { 
        handleQueryResponse(data);
        },
        "html"
    );

However, the above wasnt working very well with the google viz api (for some reason the

handleQueryResponse(data); did not trigger the function on return, so for the moment, i've coded up the following (very hackish):

var qs = '?' + 'start' + '=' +JSON.stringify(sDate) + '&' + 'stop' + '=' + JSON.stringify(eDate)
 alert(qs)
 var query = new google.visualization.Query('http://localhost:8080/'+ qs);

Above is far from a perfect sol - but in case somebody needs it in a crunch, thought this might help..

+2  A: 

You're passing a literal string containing the word sDate.
Words in the string that happen to be variable names are not magically evaluated.

Instead, you can pass an object literal, like this:

{ start: sDate },
SLaks
doesnt seem to work either - start isnt a var, its a string literal, so even if i do { 'start': sDate }, - that still doesnt include a payload in the url ?
sadhu_
It works for me. What version of jQuery are you using?
SLaks
+3  A: 

Have you tried to remove the quotes from the "{'start':sDate}" parameter? It looks like you're sending that in as a string. Try:

{'start':sDate}
gurun8
thats seemed the most likely candidate, so i did indeed try that first - but in that case the resulting url in the GET (according to firebug at least) becomes 'localhost:8080' with no additional data passed.
sadhu_
You might try appending the sDate on the URL string like this: "http://localhost:8080/?start=" + sDate
gurun8