[英]ajax data parameter how to pass json including query-string urls
我有個問題 。 在json上工作。 現在一切都很好,我知道如果我傳遞包含查詢字符串網址的json不能像這樣工作
這是一個json示例
var json='{"nodeDataArray": [
{"info":"this si child 1 from step 1", "link":"https://www.google.co.in?check=abc&"}
]}';
我用下面的ajax方法發送此代碼
$.ajax({
url: base_url + '/createflowchart/saveflowchart',
type: 'POST',
datatype: 'json',
data: "flowchartname=" + flowchartname + "&chartcode=" + chartcode + "&content=" + json,
beforeSend: function() {
$('#SaveButton').text('saving...');
// do some loading options
},
success: function(data) {
//code
},
complete: function() {
// success alerts
$('#SaveButton').text('Save');
},
error: function(data) {
alert("There may an error on uploading. Try again later");
},
});
現在的問題是
如果我傳遞包含此類URL的json https://www.google.co.in?check=abc&check=2
它將它拆分為帶有&
的post參數,但我不希望這樣做。 任何人都知道我該如何做到這一點。任何幫助都會得到應用
提供data
參數作為對象,jQuery會為您編碼:
data: {
'flowchartname': flowchartname,
'chartcode': chartcode,
'content': json
}
因此,通常最好的做法是以對象形式向$.ajax
調用提供數據,而不是手動構建難看的查詢字符串。
修改后的@rory的答案
data: {
'flowchartname': flowchartname,
'chartcode': chartcode,
'content': json,
},
它對我有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.