easyUI jQuery form ajax


1.  https://www.jeasyui.com/demo/main/index.php?plugin=Form&theme=default&dir=ltr&pitem=

  1. function loadLocal(){
  2. $('#ff').form('load',{
  3. name:'myname',
  4. email:'mymail@gmail.com',
  5. subject:'subject',
  6. message:'message',
  7. language:'en',
  8. accept:true
  9. });
  10. }
  11. function loadRemote(){
  12. $('#ff').form('load', 'form_data1.json');
  13. }
2.
The solution is to set the response Content-Type as text/plain. To do this I used below code

http://crazytechthoughts.blogspot.com/2011/01/get-json-data-response-with-jquery-form.html

3.
*
I changed the line 7524 in jquery.easyui-1.3.6.js ("onload" instead "load"):
 _44e.bind("onload", cb);


4.
I had the same issue and fixed it by setting Content-type = "text/html" in the
response header for all IE requests (rather than "application/json")

https://stackoverflow.com/questions/8892819/ie8-treats-json-response-as-file-and-tries-to-download-it


5. API

http://www.w3big.com/zh-TW/jeasyui/plugins-form-form.html
https://www.jeasyui.com/documentation/form.php
https://www.jeasyui.com/demo/main/index.php?plugin=Form&theme=default&dir=ltr&pitem=

6.

做一個提交操作。

https://www.itread01.com/content/1549513093.html

  1. // call 'submit' method of form plugin to submit the form   
  2. $('#ff').form('submit', {   
  3.     url:...,   
  4.     onSubmit: function(){   
  5.         // do some check   
  6.         // return false to prevent submit;   
  7.     },   
  8.     success:function(data){   
  9.         alert(data)   
  10.     }   
  11. });


7.

https://www.jeasyui.com/forum/index.php?topic=8246.0


8.https://www.jeasyui.com/forum/index.php?topic=3541.0


9. form error message

$('#ff').form('submit', {
success: function(data){
try{
var data = eval('('+data+')');
if (data.success){
console.log('ok')
}
} catch(e) {
console.log('err')
}
}
})

9.      jQuery EasyUI form表单不是ajax方式提交,而是在提交的时候新建一个隐藏的iframe并在iframe里面创建一个与绑定表单一样的表单,然后在iframe里面进行同步提交而不是异步提交,提交时只刷新iframe里面的页面,而在iframe外面的页面看来就像是异步提交了,这样做有一个好处——能上传文件或者图片,因为ajax方式是无法上传文件的。但是jQuery的form方法处理响应返回值(比如json)的时候没有像ajax、get、post这几个方法方便,如果处理json响应需要自己调用eval来转换成js的json对象,像下面这样:

https://blog.csdn.net/wangzuxi/article/details/43966357


————————————————

版权声明:本文为CSDN博主「zuxi」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/wangzuxi/article/details/43966357


10.

Code:
<script type="text/javascript">
$.extend($.fn.form.methods, {
loadRemote: function(jq, param){
return jq.each(function(){
var f = $(this);
$.ajax({
url: param.url,
data: param.params||{},
dataType: 'json',
success: function(data){
f.form('load', data);
}
});
})
}
})
</script>


Usage example:

Code:
$('#fm').form('loadRemote', {url:'getItem.ashx',params:{itemId:'itemId}});

留言

這個網誌中的熱門文章

考績被打差了 輕率離職會更傷

Arrays - DS (Reverse array) [Easy]

WireMock