Ajax的使用

 

在jsp页面中:
  $.ajax({
        type: "POST",// or get
        contentType: "application/json; charset=utf-8",
        url: url,
        data: "{'countryModel':" + JSON.stringify(countryModel) + "}",
        dataType: "json",//html,xml,script
        async: true, //true 表示异步,默认就是true
        success: function(data) {
    //deal with the data


        },
        error: function() {
            // deal with error
        }
    });

 

配置:ajax 的配置要写在json中;
<struts>   
 <package name="statusjson" extends="json-default" >
        <action name="search_status" class="statusAction" method="searchStatus">
   <result name="success" type="json">
    <param name="root">json</param>
   </result>
   <interceptor-ref name="defaultStack"></interceptor-ref>
     </action>
 </package>
</struts>


在Action中,要包含属性json: private JSONArray json;
给json赋值的方式:
(1)json=JSONArray.fromObject("['1']");
(2)json=JSONObject.fromObject(map)
(3)json=JSONObject.fromObject(list)

 

你可能感兴趣的:(ajax的使用)