0

この ajax コードの以前のバージョンはgoogle-chrome --disable-web-security、選択要素にオプションを入力してテスト中に完全に機能しましたが、jsonp で機能するようにコードを少し書き直したので、機能せず、修正方法がわかりません。

jQuery.ajax({
    url: xmlrpcproxy + '?callback=jsonpcallbackfunc', // <--- returns valid json if accessed in the browser
    type: "GET",
    cache: false,
    contentType: "jsonp", // Pay attention to the dataType/contentType
    dataType: 'jsonp', // Pay attention to the dataType/contentType
    jsonpCallback: 'jsonpcallbackfunc',
    });

function jsonpcallbackfunc (data) {
    var firstoption = '<option value="select" selected>Please Select</option>';
    jQuery("select#ItemIDSelect").html(firstoption);
    var i;
    var erplist = JSON.parse(data);
    alert(data);
    for (i = 0; i < erplist.length; ++i) {
                jQuery("select#ItemIDSelect").append('<option value="' + erplist[i] + '">' + erplist[i] + '</option>');
    }
    }

呼び出されたサーバー ページが返されます

jsonpcallbackfunc(["admin2", "Administrator", "Afdeling XCV", "Agrolait", "Angel Cook", "Arthur Gomez", "ASUSTeK", "Axelor", "Axelor", "Ayaan Agarwal", "Bank Wealthy and sons", "Benjamin Flores", "Best Designers", "Brian Williams", "Camptocamp", "Chamber Works", "Chao Wang", "Charlie Bernard", "China Export", "Clement Marsot", "Coin gourmand", "Daniel Jackson", "David Simpson", "Delisle Albert", "Delta PC", "Demo User", "Donald Thompson", "Edward Foster", "Elec Import", "Epic Technologies", "Fabian Semal", "George Wilson", "Global Solutions", "Jacob Taylor", "Jacque Marseille", "James Miller", "Jan Bart", "Jessica Dupont", "John M. Brown", "Joseph Walters", "Julia Rivero", "Kevin Clarke", "Laith Jubair", "Laura Castro", "Lucas Jones", "Luc Maurer", "Luminous Technologies", "Mark Davis", "Marketing Business", "Mediapole", "Michel Fletcher", "Millennium Industries", "Morgan Rose", "Natuurpunt vzw", "Nebula Business", "Nhomar Hernandez", "Paul Williams", "Peter Mitchell", "Phillipp Miller", "Pizza Inn", "Richard Ellis", "Robert Anderson", "Robin Smith", "Roger Scott", "Seagate", "Sergio P\u00e9rez", "Spark Systems", "Steven Hamilton", "Tang Tsui", "Template User", "The Jackson Group", "The Poste", "Think Big Systems", "Thomas Passot", "Tom Pintens", "Vauxoo", "Vicking Direct", "William Thomas", "Your Company", "Your Company, Birmingham shop", "Your Company, Chicago shop", "Zhi Ch'ang"])

更新: 関数が起動し、select 要素に静的オプションが追加されます。ただしvar erplist = JSON.parse(data);、予期しないトークンを取得します (admin2 から) JSON.parse(data) が失敗しないようにするには、何を変更する必要がありますか?

読んでくれてありがとう!

4

0 に答える 0