Ajax to Asmx请求仅适用于localhost

时间:2014-04-08 10:34:16

标签: asp.net ajax web-services localhost asmx

这是请求:

            var xCoordinateString = 111;
            var yCoordinateString = 111;
            $.ajax({
                type: "POST",
                url: "InsertCoordinates.asmx/Insert",
                data: { xCoordinates: xCoordinateString, yCoordinates: yCoordinateString },
                success: function (response) {
                    alert('yes');
                },
                error: function (data) {
                    alert('no');
                } 

            });

这是webservice中的Insert函数:

public void Insert(string xCoordinates, string yCoordinates)
        {
            string[] xCoords = xCoordinates.Split(',');
            string[] yCoords = yCoordinates.Split(',');

            //The following is a ZIP operation which allows you to do a foreach loop on two arrays.
            var xANDyCoordinates = xCoords.Zip(yCoords, (x, y) => new { xCoord = x, yCoord = y });

            foreach (var xy in xANDyCoordinates)
            {
                SqlConnection connection = new SqlConnection(GetConnectionString());
                connection.Open();
                SqlCommand cmd = new SqlCommand();
                cmd = new SqlCommand("InsertIndividualHeatMapCoordinates", connection);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("xCoord", xy.xCoord));
                cmd.Parameters.Add(new SqlParameter("yCoord", xy.yCoord));                
                cmd.ExecuteNonQuery();
            }            
        }

但是,只有当我使用远程桌面连接访问我的服务器并打开http://localhost:8032/

时才会推送数据

使用我的机器并访问http://networkname11:8032/ - (已中止)

enter image description here

0 个答案:

没有答案