Easyui form 处理 Laravel 返回的 Json 数据

时间:2024-11-16 00:08:01

默认地,Easyui Form 请求的格式是 Html/Text,如果服务端 Laravel 返回的数据是 Json 格式,则应当在客户端进行解析。以下是 Easyui 官方文档的说明:

Handle submit response

Submitting an ajax form is very simple. Users can get the response data when the submission is finished. Notice that the response data is the raw data from server. A parse action to the response data is required to get the correct data.

For example, response data is assumed to be JSON, a typical response data may look like this:

  1. {
  2. "success": true,
  3. "message": "Message sent successfully."
  4. }

Now handle the JSON string in 'success' callback function.

  1. $('#ff').form('submit', {
  2. success: function(data){
  3. var data = eval('(' + data + ')'); // change the JSON string to javascript object
  4. if (data.success){
  5. alert(data.message)
  6. }
  7. }
  8. });