开发者

Jquery get ... mixing json and non-json data?

开发者 https://www.devze.com 2023-03-26 11:44 出处:网络
I have something like this on a jsp page var json_text = JSON.stringify(rows, null, 2); $.get(\"/myapp/CountQuery.action\",

I have something like this on a jsp page

   var json_text = JSON.stringify(rows, null, 2);
   $.get("/myapp/CountQuery.action", 
        {output: output,
         table: table,
         stringRows: json_text
        },
              function(data) {                
                     var text = JSON.stringify(data);
                 alert('Here is the data received ' + text);
              });

I use json2.js for my JSON needs whichs works very well. So, the stringRows I am passing is json data. The output and table however are taken from the value of textfield eleme开发者_如何学JAVAnts on my page. It does not make sense to mix stringRows with output and table given what they represent. Perhaps if need be, I can create a second json object containing output and table. In the function, I am getting back JSON data sent to me by a Struts 2 action with result type JSON which gives me back valid JSON data.

Here is what is happening. If I remove both output and table from my jquery call, I see log messages in oc4j and everything looks good. If I remove just stringRows, I see log messages in oc4j and everything looks good. If I have output, table and stringRows, the alert message does get activated, but I do not see any logs indicating something is not quite right. JSON data is present in the text variable in my function above, but I don't know what is actually happening.

So my question is: Is mixing the json and non-json data inherently bad and if so which level is being fooled? I have seen other user 'json' in their jquery get calls, so I imagine it might have something to do with this.

EDIT

Too long for a comment, so here is my response:

@kingjiv I develop constantly in ie, so sometimes I do forget to check the logs. So running in chrome, the message I get is GET http://localhost:8080/myapp/CountQuery.action?output=APPN%2CBSO%2CLI&table=mytable&stringRows=%5B%0A++%5B%0A++++%22%22%2C%0A++++%22%22%2C%0A++++%22ADD%22%2C%0A++++%22%3D%22%2C%0A++++%22A%22%2C%0A++++%22%22%2C%0A++++%22AND%22%2C%0A++++%22%22%0A++%5D%2C%0A++%5B%0A++++%22%22%2C%0A++++%22%22%2C%0A++++%22D%2FR%22%2C%0A++++%22%3D%22%2C%0A++++%22D%22%2C%0A++++%22%22%2C%0A++++%22AND%22%2C%0A++++%22%22%0A++%5D%2C%0A++%5B%0A++++%22%22%2C%0A++++%22%22%2C%0A++++%22CIVPER%22%2C%0A++++%22%3D%22%2C%0A++++%22N%22%2C%0A++++%22%22%2C%0A++++%22AND%22%2C%0A++++%22%22%0A++%5D%0A%5D 404 (Not Found)


The comment by kingjiv was all it took to get my mind moving. Here is what I changed it to

   var json_text = JSON.stringify(rows, null, 2);
   $.ajax({
        type: "POST",
        url: "/myapp/CountQuery.action", 
        data: "output=" + output + "&table=" + table + "&stringRows=" + json_text, 
        success: function(msg) {                  
           var text = JSON.stringify(msg);
       alert(text);
        }
   });

Now, my logging is happy to report to me what I need to know.

0

精彩评论

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