0

以下に示すような jquery を使用しています ?Handler はコードを正しく実行し、返されるのは json の形式 (例: [{"res":1}] ) であるため、成功したものを取得するかどうかを確認したかった関数は最初にアラートを出しましたが、アラート自体は表示されていません。何が問題なのですか? よろしくお願いします。

 <script type="text/javascript">

function DoneClick() {
    alert("OO");
    var checkLocation = "";
    var txtMM = document.getElementById("hdn_Tagging").value; ///Id s of textbox assigned in code behind MB--
    txtMM = txtMM.slice(0, - 1);
    var arrTxtMM = txtMM.split(",");

    for (var j = 0; j < arrTxtMM.length; j++) {
        var Loc = document.getElementById(arrTxtMM[j]).value;
        if (Loc == "") {
            checkLocation = "";
            break;
        } else {
           checkLocation += Loc + ":";
        }
    }
    if (checkLocation != "")
    {
        var url = 'Handler/newExifDetails.ashx?Id=' + txtMM + '&Location=' + checkLocation + '';
        alert(url);
        alert("yes");
         $(document).ready(function() {
            var url = 'http://localhost:4880/Handler/newExifDetails.ashx?Id=' + txtMM + '&Location=' + checkLocation + '';
                                $.ajax({
                                url : url,
                                type: "POST",
                                dataType: "json",
                                success: function(data) {
                                alert(data);
                                alert("yeah");
                                },
                                error: function(data) { alert("error"); }
                               });
                                }); 
          });

    }
     else
     {
        alert("Please pick the locations for all objects");
    }
}
                    </script>

ここでの問題は、ハンドラーページにブレークポイントを配置したかのようにハンドラーページが呼び出され、正しく実行されていることです....そしてresponse.writeがあり、json文字列を次のように取得しています:例:[{"res" :1}] 今成功: $.ajax でアラートを書いた場合、何が問題なのかが表示されませんか???

ハンドラー コードは次のとおりです。

using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.Script.Serialization;
using System.Collections.ObjectModel;
using ClassLib_BLL;
using System.IO;
using System.Web.UI;
using System.Net;
using System.Collections.Generic;

namespace QlixooWeb.handler
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    public class UserUploadsDTO
    {
        private int _res;
        public int res { get { return _res; } set { _res = value; } }
    }

    public class newExifDetails : IHttpHandler
    {
        public static readonly UserUploadsBLL oUserUploadsBll = new UserUploadsBLL();
        string[] splitQueryStr, arId, arLocation;
        public string Id1, Location1;

        public void ProcessRequest(HttpContext context)
        {
            //context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            Collection<UserUploadsDTO> collection = new Collection<UserUploadsDTO>();
            UserUploadsDTO dto;
            string RId = context.Request.QueryString["Id"].ToString();
            string RLocation = context.Request.QueryString["Location"].ToString();
            //string json = new StreamReader(context.Request.InputStream).ReadToEnd();//Location = Bangalore%2C+Karnataka%2C+India%3AChittur%2C+Kerala%2C+India %3A  &  Id=4%2C94
            //splitQueryStr = json.Split('&');
            //Location1 = splitQueryStr[0];
            //Id1 = splitQueryStr[1];
            //string Location = RLocation.Substring(Location1.IndexOf('=', 0) + 1);
            string Location = RLocation;
            //Location = Location.Replace("%2C+", ",");
            //Location = Location.Replace("%3A", ":");
            //Location = Location.Replace("+", " ");
            Location = Location.TrimEnd(':');
            arLocation = Location.Split(':');
            string Id = RId;
            //string Id = RId.Substring(Id1.IndexOf('=', 0) + 1);
            //Id = Id.Replace("%2C", ",");
            arId = Id.Split(',');
            int res = 0;
            for (int i = 0; i < arId.Length; i++)
            {
                int UpId = Convert.ToInt32(arId[i]);
                Coordinate coordinate = Geocode.GetCoordinates(arLocation[i]);
                decimal latitude = coordinate.Latitude;
                decimal longitude = coordinate.Longitude;
                res = oUserUploadsBll.TaggingImages(latitude, longitude, UpId);
            }
            if (res > 0)
            {
                dto = new UserUploadsDTO();
                dto.res = res;
                collection.Add(dto);
            }
                //context.Response.Redirect("~/UserUploads.aspx");
                //context.Response.Write(res);
            else
                context.Response.Write("false");
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string jsonString = serializer.Serialize(collection);
            context.Response.Write(jsonString);

        }
        public interface ISpatialCoordinate
        {
            decimal Latitude { get; set; }
            decimal Longitude { get; set; }
        }
        /// <summary>
        /// Coordiate structure. Holds Latitude and Longitude.
        /// </summary>
        public struct Coordinate : ISpatialCoordinate
        {
            private decimal _latitude;
            private decimal _longitude;
            public Coordinate(decimal latitude, decimal longitude)
            {
                _latitude = latitude;
                _longitude = longitude;
            }
            #region ISpatialCoordinate Members
            public decimal Latitude
            {
                get { return _latitude; }
                set { this._latitude = value; }
            }
            public decimal Longitude
            {
                get { return _longitude; }
                set { this._longitude = value; }
            }
            #endregion
        }
        public class Geocode
        {
            private const string _googleUri = "http://maps.google.com/maps/geo?q=";
            private const string _googleKey = "AIzaSyB4UgLW37a1jhxnnz5J27KPNaHIDmapSYk";
            private const string _outputType = "csv"; // Available options: csv, xml, kml, json
            private static Uri GetGeocodeUri(string address)
            {
                address = HttpUtility.UrlEncode(address);
                return new Uri(String.Format("{0}{1}&output={2}&key={3}", _googleUri, address, _outputType, _googleKey));
            }
            public static Coordinate GetCoordinates(string address)
            {
                WebClient client = new WebClient();
                Uri uri = GetGeocodeUri(address);
                /* The first number is the status code, 
                * the second is the accuracy, 
                * the third is the latitude, 
                * the fourth one is the longitude.
                */
                string[] geocodeInfo = client.DownloadString(uri).Split(',');
                return new Coordinate(Convert.ToDecimal(geocodeInfo[2]), Convert.ToDecimal(geocodeInfo[3]));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

また、aspxページでは、次のように2つのスクリプトタグを使用しました:

<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>

<script src="js/jquery-latest.js" type="text/javascript"></script>

これは、head タグ内で使用されます... aspx ページの... Handler を呼び出している場所から..

4

4 に答える 4

0

問題はおそらく、jQuery ajax 呼び出しが文字列内の "%2c" を処理できないことです。

于 2013-10-08T12:27:30.427 に答える
0

あなたが投稿したコードには何も問題はありません。私はそれをフィドルで試してみましたが、正しく動作します。ここを参照してください: http://jsfiddle.net/zk8Nk/

ページに邪魔になっている他のスクリプトが含まれている可能性がありますが、ページ全体を確認しないとどうすることもできません。

于 2012-09-24T07:58:50.363 に答える
0

次のことを試すこともできます。

$.post("http://localhost:4880/Handler/newExifDetails.ashx", { "Id": txtMm },
   function(data){
      alert('test');
   }
   ,"json"
);

http://api.jquery.com/jQuery.post/

これは、あなたが今書いたものを別の書き方で表したものです。これが機能しない場合は、FireBug を試してみて、FireBug の内容を確認してください。

于 2012-09-24T07:56:10.403 に答える
0

を変更してみてくださいtype:'GET'

POST として設定するため、クエリ文字列ではなく、データ内のパラメーターが必要です。

var url = 'http://localhost:4880/Handler/newExifDetails.ashx;

     $.ajax({
         url: url,
         type: "POST",
         data : {'Id' : txtMM , 'Location' : checkLocation},

または

var url = 'http://localhost:4880/Handler/newExifDetails.ashx?Id=' + txtMM + '&Location=' + checkLocation + '';

 $.ajax({
     url: url,
     type: "GET",
于 2012-09-24T07:56:52.043 に答える