1

これは私のJsonExample.jspファイルです。

    <!DOCTYPE html>
        <html>
        <title>jQuery Function Demo - jQuery4u.com</title>
        <head>
        <script
            src="http://www.jquery4u.com/function-demos/js/jquery-1.6.4.min.js"></script>
        <script src="http://www.jquery4u.com/scripts/function-demos-script.js"></script>


        <script>
            function call() {

                //var url = 'http://192.168.10.82:8081/formulator-service/tracks?callback_track=processJSON';

                var url = "http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=processJSON&tags=monkey&tagmode=any&format=json";

                $.ajax({
                    type : "GET",
                    url : url,
                    async : false,
                    jsonpCallback : "processJSON",
                    contentType : "application/json",
                    dataType : "jsonp",
                    success : function(json) {

                        alert(json.title);
                        //alert(json.name);

                        controllerCaller(json);

                    },
                    failure : function() {
                        alert("There is some error");
                    }
                });

            }
            function controllerCaller(json) {
                //var dummy = "poiuytre";

                alert("in the Controller caller");
                //var url="/controllerCall";
                $.ajax({
                    type : "POST",
                    url : "controllerCall",
                    async : false,
                    data : {
                        jsondata : json
                    },
                    success : function() {
                        alert("In controller Ajax function");
                    },
                    failure : function(error) {
                        alert("somthing went wrong");
                    }

                });
            }
        </script>


        </head>
        <body>
            <button onclick="call()">Get Json</button>
        </body>
        </html>

これは私のBaseController.javaファイルです

package com.web.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/")
public class BaseController {

    @RequestMapping(method = RequestMethod.GET)
    public String printHello(ModelMap model) {

        return "Jsonpexample";

    }

    @RequestMapping(value = "/controllerCall", method = RequestMethod.POST, produces = "json/application")
    public @ResponseBody
    String controllerCall(
            @RequestParam(value = "jsondata", required = true) String data) {
        System.out.println("this is in the second function");

        return data;

    }

}

問題は、ビューによって送信されたデータをコントローラーで受信できないことです。誰かがそうする適切な方法を提案できますか? ありがとうございました。

4

1 に答える 1