首页 \ 问答 \ Spring框架的核心概念是什么?需要掌握的知识点都有哪些?

Spring框架的核心概念是什么?需要掌握的知识点都有哪些?

RT。。恳请指教。。thanks so much!
更新时间:2023-12-21 20:12

最满意答案

根据我的经验,尝试解析ajax响应的类型往往是超级不可靠的。

出于这个原因,我(现在)确保每当我编写一个用于返回ajax数据的服务器端函数时,我保持它完全符合我自己的set response“standard”,然后在我的响应中设置我的响应类型JSON的ajax方法。

这样做可以使处理错误更加可预测。

标准化响应的一个例子是:

$ajaxResponse = array(
  'data' => $someData,
  'result' => true,
  'message' => 'your yadayada was succesful',
  'timestamp' => time()
);
print json_encode($ajaxResponse);

在ajax中,您的回答如下:

success: function( response ) {
   if(response.result) {
      alert(response.message);
   }
}

Trying to parse the type of an ajax response tends to be super unreliable, in my experience.

For that reason, I (now) make darn sure that whenever I write a server side function that is meant for returning ajax data, I keep it perfectly in line with my own set response "standard", and then set my response type in the ajax method to JSON.

Doing so makes handling errors much more predictable.

An example of a standardized response would be:

$ajaxResponse = array(
  'data' => $someData,
  'result' => true,
  'message' => 'your yadayada was succesful',
  'timestamp' => time()
);
print json_encode($ajaxResponse);

and in ajax, your response would be like:

success: function( response ) {
   if(response.result) {
      alert(response.message);
   }
}

相关问答

更多
  • 根据我的经验,尝试解析ajax响应的类型往往是超级不可靠的。 出于这个原因,我(现在)确保每当我编写一个用于返回ajax数据的服务器端函数时,我保持它完全符合我自己的set response“standard”,然后在我的响应中设置我的响应类型JSON的ajax方法。 这样做可以使处理错误更加可预测。 标准化响应的一个例子是: $ajaxResponse = array( 'data' => $someData, 'result' => true, 'message' => 'your yada ...
  • 你不能使用JSONP来开发...它根本不起作用,它创建一个