weixin_33743880 2017-01-11 16:02 采纳率: 0%
浏览 20

不创建新的ajax请求

A new get ajax request should be created (even if there is any outstanding ajax request) whenever:-

1) i input any string and press enter (with the help of terminal api).

2) and key-event ajax request when i press ctrl^D ( or C, O,etc). [my code]

But after creating numerous (7 to 8) ajax requests (which are still running), i am not able to create new key-event ajax request. What shall be changed in this code?

<script>
jQuery(document).ready(function($) {
  var id = 1;
  document.addEventListener("keyup", function(event) {

    if(event.ctrlKey) {
      switch (event.which) { 
      case 67: 
        input_signal='__%ctrl+C%__';
        break;
      case 68: 
        input_signal='__%ctrl+D%__';
        break;
      case 90: 
        input_signal='__%ctrl+Z%__';
        break;
      }
      /*--------KEY-EVENT AJAX GET REQUEST CODE-------------*/

      $('body').ajaxStart(function(){
        $.get('/terminal_exec',{input: input_signal}, function(){
          //input_signal='process quit');
        });
      });
      console.log( "You pressed "+input_signal );
      event.preventDefault()

      /*------------------------------------------------*/
    }
  })

  $('body').terminal(function(command, term) {
    if (command == 'help') {
      term.echo('yoyo man');
    } else {
      /*--------INPUT STRING AJAX GET REQUEST CODE-------------*/
      $.get('/terminal_exec',{input: command}, function(data){
        term.echo(data);
      });
      /*----------------------------------------------------*/
    }
  }, {
    greetings: "HEY",
    onBlur: function() {
      // prevent loosing focus
      return false;
    }
  });
});

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 gojs 点击按钮node的position位置进行改变,再次点击回到原来的位置
    • ¥15 计算决策面并仿真附上结果
    • ¥20 halcon 图像拼接
    • ¥15 webstorm上开发的vue3+vite5+typeScript打包时报错
    • ¥15 vue使用gojs,需求在link中的虚线上添加方向箭头
    • ¥15 CSS通配符清除内外边距为什么可以覆盖默认样式?
    • ¥15 SPSS分类模型实训题步骤
    • ¥100 求ASMedia ASM1184e & ASM1187e 芯片datasheet/规格书
    • ¥15 求解决扩散模型代码问题
    • ¥15 工创大赛太阳能电动车项目零基础要学什么