开发者

using jQuery $get to pull data

开发者 https://www.devze.com 2023-01-02 19:24 出处:网络
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.

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..


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}


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 },
0

精彩评论

暂无评论...
验证码 换一张
取 消