How to handle jQuery.ajax(..) JSON request ?
2013-04-28 10:12
381 查看
Apache Wicket > Framework Documentation > Reference library > How to do things in Wicket > AJAX > How to handle jQuery.ajax(..) JSON request ? |
How to handle jQuery.ajax(..) JSON request ?
Edit Page
Browse Space
Add Page
Add News
#editReport()
The following is the jQuery JSON request code
This section of code invokes a abstract behavior ona page with a json request:
console.log(" call back url :"+ callBackURL); $.ajax({ url: callBackURL, type: 'post', cache: false, data:JSON.stringify(ccbArry), contentType: 'application/json; charset=utf-8', dataType: 'json', success: function(json) { console.log(" reponse :"+ json); }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log("error :"+XMLHttpRequest.responseText); } });
This section of code is an abstract ajax behavior which accepts a json document in request and responds with another json document that is then available to the javascript method on the page.
AbstractAjaxBehavior ajaxSaveBehaviour = new AbstractAjaxBehavior(){ private static final long serialVersionUID = 1L; @SuppressWarnings("unchecked") public void onRequest() { //get parameters final RequestCycle requestCycle = RequestCycle.get(); WebRequest wr=(WebRequest)requestCycle.getRequest(); HttpServletRequest hsr= wr.getHttpServletRequest() ; try { BufferedReader br = hsr.getReader(); String jsonString = br.readLine(); if((jsonString==null) || jsonString.isEmpty()){ logger.error(" no json found"); } else { logger.info(" json is :"+ jsonString); } } catch (IOException ex) { logger.error(ex); } // json string to retir to the jQuery onSuccess function String data=getReturnJSONValue(); logger.info("returning json :"+ data); IRequestTarget t = new StringRequestTarget("application/json", "UTF-8", data); getRequestCycle().setRequestTarget(t); //requestCycle.setRequestTarget(new StringRequestTarget("application/json", "utf-8", data)); } }; add(ajaxSaveBehaviour); String callBackURL= ajaxSaveBehaviour.getCallbackUrl().toString(); logger.info(" callback url :"+ callBackURL);
Generated by Atlassian Confluence (Version: 3.4.6 Build: 2036 Dec 21, 2010)
Auto Export Plugin (Version: 1.0.0-dkulp)
相关文章推荐
- How to use jquery ajax and android request security RESTful WCF
- How to get pure json data by ajax request
- How to use JSon data in mvc action and post form data use JQuery ajax
- How To Generate JSON With PHP and Parse It With JQuery
- Send and Receive JSON objects to Web Service Methods using jQuery AJAX in ASP.Net
- jquery ajax send json to action and get response from action
- [转]How to override HandleUnauthorizedRequest in ASP.NET Core
- Passing a list of objects from view to controller via jquery ajax(Json(aspx) -> object(C#))
- How to format a JavaScript date(jquery ,json ,日期)
- jquery通过ajax-json访问java后台传递参数,通过request.getParameter获取不到参数的说明
- How to solve “jQuery not working in AJAX loaded elements”
- 参照jQuery.ajax改造tangram的baidu.url.jsonToQuery()方法使之支持json嵌套对象的解析
- How to use jquery or ajax to update razor partial view in c#/asp.net for a MVC project
- jquery通过ajax-json访问java后台传递参数,通过request.getParameter获取不到参数的说明
- jquery通过ajax-json访问java后台传递参数,通过request.getParameter获取不到参数的说明
- when jquery.ajax() call wcf,if success,how to use wcf return value?
- How to POST a django form with AJAX & jQuery
- jquery通过ajax-json访问java后台传递参数,通过request.getParameter获取不到参数的说明
- csharp:Learn how to post JSON string to generic Handler using jQuery in ASP.Net C#.
- How To Replace jQuery 1.9.1's $.parseJSON function with the implementation from jQuery 1.8.3