2014-10-02 29 views
6

ajax ile bir istek göndermeye çalışıyorum ama 400 hatalı durum isteğim var. Ne tür bir veri göndermeli ve denetleyicide veri nasıl alınmalı? O isteği tek parametre yanlış bir şeyi olmadığına eminimSpring Framework'de parametre ile ajax isteği nasıl gönderilir ve gönderilir?

jsp

<script type="text/javascript"> 

    var SubmitRequest = function(){ 
     $.ajax({ 
       url : "submit.htm", 
       data: document.getElementById('inputUrl'), 
       type: "POST", 
       dataType: "text", 
       contentType: false, 
       processData: false, 
       success : 
        function(response) { 
         $('#response').html(response); 
        } 
     }); 
    } 
    </script> 

kontrolör

@RequestMapping(value = "/submit", method = RequestMethod.POST) 
public @ResponseBody 
String Submit(@RequestParam String request) { 
    APIConnection connect = new APIConnection(); 
    String resp = ""; 
    try { 
     resp = "<textarea rows='10'cols='100'>" + connect.doConnection(request) + "</textarea>"; 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     resp = "<textarea rows='10'cols='100'>" + "Request failed, please try again." + "</textarea>"; 
    } 
    return resp; 
} 

cevap

25

bir Ajax sonrası isteği göndermek için, bu kullanabilirsiniz:

$.ajax({ 
    type: "POST", 
    url: "submit.htm", 
    data: { name: "John", location: "Boston" } // parameters 
}) 

Ve Spring MVC'de denetleyici:

@RequestMapping(value = "/submit.htm", method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE) 
public @ResponseBody 
String Submit(@RequestParam("name") String name,@RequestParam("location") String location) { 
    // your logic here 
    return resp; 
} 
+0

Teşekkürler, işe yarıyor! – Bboy820602

+0

Size yardımcı olmaktan memnuniyet duyarım. – Pracede

İlgili konular