私はSAPのサービス層に接続し、URL(API REST)からクエリを作成するアプリケーションを開発中です。私はfamouseウィジェットselect2を使用していますが、私は問題があります。私は、APIにクエリを作成する必要があり、その文は、(」「)空白文字があります。Select2ウィジェットはajaxに "+"と%20でないparam.termスペースを送信します。
"(startswith(CardCode,'"+params.term+"') or startswith(CardName,'"+params.term+"'))
スペースが周りのものであり、 『または』演算子。
だから、これはマイルコードです:
$('#buscarCliente').select2({
placeholder: "Ingrese código o descripción del cliente",
allowClear: true,
language: "es",
ajax: {
url: SLServer+"BusinessPartners",
crossDomain: true,
xhrFields: {
withCredentials: true
},
dataType: 'json',
type: 'GET',
delay: 550,
params: {
contentType: 'application/raw; charset=utf-8'
},
data: function (params) {
return {
$filter: "(startswith(CardCode,'"+params.term+"') or startswith(CardName,'"+params.term+"'))", // Como se va hacer la busqueda
$orderby : "cardName",
//contentType: 'multipart/form-data;boundary=<Boundary>',
//$filter: "((startswith(CardName,'" + params.term.toUpperCase() + "') or startswith(CardCode,'" + params.term.toUpperCase() + "') or startswith(CardName,'" + params.term + "') or startswith(CardCode,'" + params.term + "')) and CardType eq 'C')&$top=15&$expand=PaymentTermsType",
//$filter: "startswith(CardName,'" + params.term.toUpperCase() + "') or startswith(CardCode,'" + params.term.toUpperCase() + "')",
page: params.page
};
},
processResults: function (data, params) {
// parse the results into the format expected by Select2
// since we are using custom formatting functions we do not need to
// alter the remote JSON data, except to indicate that infinite
// scrolling can be used
params.page = params.page || 1;
return {
results: $.map(data.value, function(item) {
return { id: item.CardCode, text: "<b>"+item.CardCode+"</b> "+item.CardName }; //adecuamos el arreglo al select
}),
pagination: {
more: (params.page * 30) < data.total_count
}
};
},
cache: true
},
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
/*formatNoMatches: function (term) {
return 'No se encontraron clientes con el código: "' + term + '".<br/><!--span class="link">Click here</span-->',
},*/
minimumInputLength: 1,
//templateResult: formatRepo, // omitted for brevity, see the source of this page
//templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
});
あなたが見ることができるように、私はウィジェットで入力されている用語を結ぶパラメータとしてクエリを送信しています。問題は、select2が空白をプラス記号(+)で置き換えて "%20"ではないようにクエリをエンコードすることで、api restサービスはそれが不正な文字であり、結果を得ることができないということです。これは、それが見える方法です
:
https://service.net:50000/b1s/v1/BusinessPartners?%24filter=(startswith(CardCode%2C%27CLIEN%27)+or+startswith(CardName%2C%27CLIEN%27))&%24orderby=cardName
をあなたのすべてを見ることができるように、周りのスペース「または」演算子はプラス記号に置き換えられています。私はjavascript関数 "encodeUri()"と "encodeURIComponent()"をテストして、コード内でシリアライズされていると思うので何もしません。私はcontentTypeを追加しましたが、スペースを "%20"で手動で置き換えましたが、結果はエンコードされ、悪化しています(%2520)...
誰でも助けてくれますか?このタイプのエンコーディングを変更してスペースが "%20"に変更され、気が "+"変わらないようにする方法はありますか?
ありがとうございました!
私はGETリクエストを送信しているので、私はurlパラメータにクエリを追加できますが、私は検索ボックスに入力されている用語を取得する必要があることを覚えています。そのレベルでそれを得る方法を気にしないでください... –