Ajax和Node.js出现问题


                    

我遇到一个困扰我的问题。</ p>

我有一个使用php和mysql的简单网页。 我正在尝试将其转换为node.js和mysql。</ p>

有2个下拉选择框,第一个包含从数据库中获取的客户列表。 (效果很好)</ p>

选择客户后,我需要在第二个框中包含属于该客户的工具列表。</ p>

我在php版本中工作得很好,但是在node.js版本中,第二个下拉列表没有显示[日期],并且控制台显示错误并指出
不赞成在主线程上使用同步XMLHttpRequest,因为它会对最终用户的体验产生不利影响。</ p>

这是否意味着我无法使用此代码或更好的代码,但是如何更改此脚本以使其正常运行?</ p>

  $(document).ready(function(){

$(“ select#cust”)。change(function(){
var cust_id = $(“ select#cust option:selected”)。attr('value');
var test = $(“#test”)。val();
var din = $(“#idate”)。val();
$(“#inst”)。html(“”);

如果(cust_id.length> 0){
$ .ajax({
         异步:是的,
         类型:“ GET”,
         异步:是的,
         网址:“ fetch_inst”,
         数据:“ cust_id =“ + cust_id,
         快取:false,
         beforeSend:function(){
             $('#inst')。html('“”');
         },
         成功:功能(数据){
             $(“#inst”)。html(data);

         }
     });

      }
});
</ code> </ pre>
     </ div>

展开原文

原文

I am having a problem that has me perplexed.

I have a simple webpage that works using php and mysql. I am trying to conver this to node.js and mysql.

There are 2 dropdown select boxes the first contains a list of customers that is taken from the database. (This works well)

when a customer is selected I need the second box to contain a list of instruments that belong to the customer.

I have this working great in the php version but in the node.js version the second dropdown does not get up[dated and the console has and error that states Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.

Does this mean I can not use this code or better yet how do I change this script to make it work properly??

$(document).ready(function(){ 

$("select#cust").change(function(){
var cust_id =  $("select#cust option:selected").attr('value'); 
var test =  $("#test").val();
var din = $("#idate").val(); 
$("#inst").html( "" );

if (cust_id.length > 0 ) { 
$.ajax({
        async: true,
        type: "GET",
        async: true,
        url: "fetch_inst",
        data: "cust_id="+cust_id,
        cache: false,
        beforeSend: function () { 
            $('#inst').html('<img src="loader.gif" alt="" width="24" height="24">');
        },
        success: function(data) {    
            $("#inst").html( data );

        }
    });

     }
});

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐