简体   繁体   English

我需要如何将其转换为普通的 javascript 或 jquery?

[英]How do I need to convert this to plain javascript or jquery?

I'm new to JavaScript and jQuery.我是 JavaScript 和 jQuery 的新手。 I'm currenly having the following code in my javascript file, however it doesn't seem to be working.我目前在我的 javascript 文件中有以下代码,但它似乎不起作用。 I'm using this from prototype.js :我正在使用这个来自prototype.js:

        var url = '/sip/TnsViewScreenResponse';
        var myAjax = new Ajax.Request(url, {
                method: "post",
                headers:{
                    'X-Requested-By': 'XMLHttpRequest'
                 },
                 parameters: "tin=" + tin,                 
                success: function transResult(response) {
         document.getElementById('tinVersionsOf_' + tin).innerHTML 
         = response.responseText;                    
         document.getElementById('ajax_loading_img').style.display 
         = 'none';
         document.getElementById('tinVersionsOf_' + tin).style.display = 
         'block';
         },
         error: function transResult(response) {
         document.getElementById('ajax_loading_img').style.display = 'none';
         alert('Failure: Problem in fetching the Data');
               },              
            }
         );         
         return false;

This seems to be conflicting with the other jQuery files being used in the file, so I want to convert this to plain JavaScript or jQuery.这似乎与文件中使用的其他 jQuery 文件冲突,所以我想将其转换为纯 JavaScript 或 jQuery。 I have tried the below but it doesn't seem to be working.我已经尝试了以下但它似乎没有工作。 How can I make this right ?我怎样才能做到这一点?

var url = '/sip/TnsViewScreenResponse';
var myAjax = $.ajax({
  type: "POST",
  url: url,
  data: tin,
  success: function transResult(response) {
         $('#tinVersionsOf_' + tin).html(response.responseText);                    
       $('ajax_loading_img').css("display","none") ;
       $('#tinVersionsOf_' + tin).css("display","block");
         },
   error: function transResult(response) {
         $('#ajax_loading_img').hide();
         alert('Failure: Problem in fetching the Data');
               },              
            }
});

The above code is getting skipped while being parsed in the browser, which I had checked with inspect element option in Google chrome.上面的代码在浏览器中解析时被跳过,我已经在谷歌浏览器中使用检查元素选项进行了检查。

Try This尝试这个

 $.ajax({ type: "POST", dataType: "json", contentType: "application/json", url: "/sip/TnsViewScreenResponse", data: JSON.stringify({ mydata: tin }),//where tin is ur data success: function (result) { //include your stuff }, error:function(error) { // include your stuff } });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM