Home  >  Article  >  Web Front-end  >  Methods to solve the problem that JS cannot call Controller_javascript skills

Methods to solve the problem that JS cannot call Controller_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:22:341631browse

No more gossip. Take a look at the accident scene first.
Accident scene
What I have to do now is to call the background controller method through JS. You can see that the client uses Jquery and Ajax. The problem now is that js can run, but the background code cannot run the controller method.

 

My solution
The ajax code is wrong. You can see that I did not set the request method in the code, that is, synchronous request or asynchronous request. The default ajax is asynchronous request, which means that I want to use ajax here to achieve synchronization. ask.
So we need to add one more request method in ajax.         

Write ajax with jquery
The following is a way to use ajax.

$.ajax ({ 
  method //数据的提交方式:get和post 
  url //数据的提交路劲 
  async //是否支持异步刷新,默认是true 
  data //需要提交的数据 
  dataType //服务器返回数据的类型,例如xml,String,Json等 
  success //请求成功后的回调函数 
  error //请求失败后的回调函数 
 }); 

When it comes to Aajx, we may first think of asynchronous calls, which improves user experience. However, the ajax used this time adopts a synchronous method. I hope this article will be helpful to everyone's learning.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn