这个真的很奇怪.我$.post()在代码中有多个,但有一个dunno为什么发送json参数x-www-form-urlencoded而不是因此不起作用.
这是代码:
$.post("/Route/SaveTransportProperties", { properties: JSON.stringify(propArray), currTravelBox: JSON.stringify(travelBoxObj), accessToken: getAccessToken()}, function(data)
{
//DO STUFF
});
Run Code Online (Sandbox Code Playgroud)
XHR在Firefox中看起来像这样:

任何想法为什么会发生这种情况?我还将类型强制为'json',但也不起作用.
您可以包装此代码,以便在调用函数时返回包含json对象的变量吗?
例:
function GetNewSomething() {
var newtb = 0;
$.get("/something/new",
function (data) {
newtb = data;
}
);
return newtb; // as of now this always returns undefined...
}
Run Code Online (Sandbox Code Playgroud)
试过这种方式,但只返回undefined ..
先谢谢你们!
问候,
我有2个asp列表框控件和一个html输入按钮,并使用js我添加项目(以前从DB加载)从列表框A到B,它工作正常,但当我提交表单时,在列表框B后面的代码中做没有我添加的项目可访问.
我的想法是试图将往返保存到服务器并在客户端进行,但看起来它不起作用.
有任何想法吗?
非常感谢你的时间!
编辑
有代码
<asp:ListBox ID="lstBoxOrgs" runat="server" Height="117px" Width="502px" SelectionMode="Multiple"></asp:ListBox>
<input type="button" value="Add" onclick="AddItems2Listbox('lstBoxOrgs', 'lstBoxUserRelOrgs') "/>
Run Code Online (Sandbox Code Playgroud)
代码背后:
protected void AssignOrgs_Click(object sender, EventArgs e)
{
foreach (ListItem orgItem in lstBoxUserRelOrgs.Items)
{
//Update database here...
}
//Commit updates to DB
cdc.SubmitChanges();
}
Run Code Online (Sandbox Code Playgroud)
这onclick="AddItems2Listbox('lstBoxOrgs', 'lstBoxUserRelOrgs') 是将lisbox A中的项目添加到列表框B的javascript函数.
谢谢