Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Ajax代码中,成功是行不通的_Javascript_Jquery_Ajax_Node.js_Express - Fatal编程技术网

Javascript 在Ajax代码中,成功是行不通的

Javascript 在Ajax代码中,成功是行不通的,javascript,jquery,ajax,node.js,express,Javascript,Jquery,Ajax,Node.js,Express,我正在使用express、node.js和mysql。在Ajax代码中,成功不起作用。下面是Ajax代码 function GetData_1(){ var state = $("#dpState_1").val(); console.log(state); $.ajax({ url:"http://localhost:5000/postDistrict", type: "post", data: {objectData :state}, dataType

我正在使用express、node.js和mysql。在Ajax代码中,成功不起作用。下面是Ajax代码

function GetData_1(){
 var  state = $("#dpState_1").val();
 console.log(state);
 $.ajax({
 url:"http://localhost:5000/postDistrict",
     type: "post",
     data: {objectData :state},
     dataType: "json",           
     crossDomain: "true",      
     success: function (result) {
     console.log('Im reaching at the postDistrict');
     $.ajax({
           url:"http://localhost:5000/getDistrict",
           type: "get",
           dataType: "json",           
           crossDomain: "true",      
           success: function (result) {
             console.log("Inside Success")
             $.each(result,function(index,obj){
             $("#dpDistrict_1").append("<option value = " + obj.dist + ">" + obj.dist+              
              "</option>"); });   
             },
             error: function (obj, txtStatus, error) {
          alert("There was some error,could not fetch data.....");
              }
             });
            },
          error: function (obj, txtStatus, error) {
          alert("There was some error,could not fetch data... :((");
          }
        });
       }

尝试在ajax中使用异步:false

$.ajax({
        type:'POST',
        url:"ajax/cart.php",
        async:false,
        data:"prod_id="+$('#prodh_id').val()+"&qty="+$('#qty').val()+"",
        success: function(result)

如果未触发成功,则意味着您的服务器在处理请求后不会返回状态200。@setec..我只是node.js的新手,所以您可以告诉我代码中必须进行哪些更新才能正常工作…我想知道您是否在那里使用跨域调用,因为您在代码中设置了所需的标志和标题。为了帮助您进行调试,您应该运行
curl-Ihttp://localhost:5000/getDistrict
获取有关状态代码(状态200)的更多信息。顺便说一句:你有没有为getDistrict提供一条GET_路线?因为我在代码中找不到它。如果您不知道如何使用curl,请在线尝试几十个“http头查看器”服务之一。
$.ajax({
        type:'POST',
        url:"ajax/cart.php",
        async:false,
        data:"prod_id="+$('#prodh_id').val()+"&qty="+$('#qty').val()+"",
        success: function(result)