0

私は非常に奇妙な状況に陥っています。jQuery ajax 経由で呼び出していくつか<select></select>の .NET Web サービス (.asmx) を作成しようとしている .NET Web サービス (.asmx) があります。サービスはSystem.Web.Services想定どおりに実行されており、JSON リストを返す必要があります。少なくとも、それが .NET 3.5/4.0 になると私が理解している方法です。

主な問題は、.ajax()関数 (以下) は実行されているように見えますが、内部コールバックが実行されていないことです。関数の前後に何かを実行でき、両方を実行できるため、実行中であることがわかります。そのため、JavaScript が爆発することはありません。

    $.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: 'http://localhost:59191/AFEDropDownService/Service.asmx/GetAVP',
    data: "{}",
    dataType: "jsonp",
    crossDomain: true,
    success: function(list) {
        console.log(list);
        console.log("success!!");
    },
    error: function(msg) {
        console.log("error: " + msg.text);
    }
});

さらにコードが必要な場合はお知らせください。または、カスケードを構築しようとしているので、より良い方法を知っている場合<select></select

アップデート

「jsonp」から「json」に変更したところ、「undefined」のエラーメッセージに戻りました。とにかく未定義のものを見つける方法はあります? ちょっと頭がおかしいのではないかと心配しています。

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: 'http://localhost:59191/AFEDropDownService/Service.asmx/GetAVP',
    data: "{}",
    dataType: "json",
    success: function(list) {
        console.log(list);
        console.log("success!!");
    },
    error: function(msg) {
        //console.log("error: " + msg.text);
    }
});

更新 2

次の.ajaxError()コードを挿入すると、「thrownError」オブジェクトの firebug に「空の文字列」が表示されます。

$("#sel_AFE").ajaxError(function(e,xhr,settings,thrownError){
    console.log('error in: ' + settings.url + ' \n'+'error:\n' + thrownError);
});
4

2 に答える 2

0

jsonpの代わりにjsonだけを使用してみませんか。また、なぜクロスドメインを設定したのですか。

ブラウザの応答セクションにjsonpデータが表示されますか..??

代わりに使用する

error: function(msg){
       console.log("error: " + msg.text);
 } .. try Using 

error: function(jqXHR, textStatus, errorThrown){
  // log all the details here
} 
于 2012-09-12T21:36:28.830 に答える
0

jQueryのドキュメントには次のように書かれています:

jQuery.post() を使用したリクエストがエラー コードを返した場合、スクリプトがグローバルな .ajaxError() メソッドも呼び出していない限り、メッセージは表示されずに失敗します。あるいは、jQuery 1.5 以降では、jQuery.post() によって返される jqXHR オブジェクトの .error() メソッドもエラー処理に使用できます。

successおよびerrorコールバックの使用方法の例を次に示します。

// Assign handlers immediately after making the request,
// and remember the jqxhr object for this request
var jqxhr = $.post("example.php", function() {
  alert("success");
})
.success(function() { alert("second success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });

// perform other work here ...

// Set another completion function for the request above
jqxhr.complete(function(){ alert("second complete"); });
于 2012-09-13T06:40:35.120 に答える