我是一名前端开发人员.我只在客户端进行编码,所以我不确定错误是否存在.我正在搜索CORS,但仍然不知道我的问题是什么.
我正在尝试将数据发布到REST.
$.ajax({
url : urlPost,
type : "POST",
data : JSON.stringify(obj),
dataType : "json",
contentType: "application/json",
success: function(res){
console.log(JSON.stringify(res));
},
error: function(res){
console.log("Bad thing happend! " + res.statusText);
}
});
Run Code Online (Sandbox Code Playgroud)
web服务的标题显示在firefox的firebug中:

它适用于我使用的所有浏览器,除了在IE 10中,我有两个错误:
SEC7118:XMLHttpRequest用于http://mysite/project/wl.svc/AddWL/所需的跨源资源共享(CORS).
SEC7119:XMLHttpRequest用于http://mysite/project/wl.svc/AddWL/所需的CORS预检.
我在我的控制器中尝试了这个代码:
List<ProductListingModels> prom = new List<ProductListingModels>();
prom.Add(new ProductListingModels()
{
ID = item.ID,
Name = item.Name,
DepartmentID = item.DepartmentID.Value,
BrandID = item.BrandID.Value
});
jr.Data = prom;
jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return Json(new
{
ja = jr.Data,
}, JsonRequestBehavior.AllowGet);
Run Code Online (Sandbox Code Playgroud)
这是我的ProductListingModel:
public class ProductListingModels:ItemEntityDataContext
{
public int ID { get; set; }
public string Name { get; set; }
public int DepartmentID { get; set; }
public int BrandID { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是一个错误:
序列化类型的对象时检测到循环引用.
但是如果我从添加对象"prom"改为添加类似字符串或整数的东西,它就可以正常工作.我不知道如何添加我的对象会出现什么问题.
任何人都可以向我展示解决方案.欢迎您提出所有问题和答案,非常感谢.
我想在数据库中选择我的价格水平来与整数进行比较.但它是错误的:运算符'=='不能应用于'System.Linq.IQueryable'和'int'类型的操作数.这是我的代码:
if (Request.IsAuthenticated){
CustomerModels cm = new CustomerModels();
string userName = Page.User.Identity.Name;
var list_pricelevel = from c in cm.DataContext.Customers
where c.WebAccount == userName
select c.PriceLevel;
if (list_pricelevel == 3) {
Response.Write("Welcome");
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个地图路线,如:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
Run Code Online (Sandbox Code Playgroud)
但我想添加更多的路由URL,我该怎么做?
我创建了一个方法将json数据发布到Web服务:
function WishList() { }
WishList.prototype.addToWishList = function(redirectURL, postURL, userObj) {
$.ajax({
type: "POST",
url: postURL,
data: JSON.stringify(userObj),
dataType: 'json',
contentType: "application/json",
success: function(data){alert(data);},
failure: function(errMsg) {
alert(errMsg);
}
}
This is my object:
var user1 = {
ID:1,
Sex:1,
Name:"titi",
Company:"ABC",
Address:"Phnom Penh",
Email:"test.abc@gmail.com",
Phone:"011123456",
WebAccount:"test.abc@gmail.com",
Password:"123456",
GroupCustomerID:125,
Stars:1,
IsVIP:0,
PriceLevel:1,
LastDateSale:"\/Date(-62135596800000)\/",
TotalCredit:150.12,
AgingData:null,
TotalRedeemPoint:1000.00,
RedeemData:null,
ExchangeRate:155.00,
HistoryData:null
};
Calling function :
$(document).ready(function () {
var myWishList = new WishList();
$('#addToWishList').click(function(){
myWishList.addToWishList('http://www.blahblahblah.com' , 'http://blahblah/Website/Products/Product.svc/Wishlist/' , user1);
});
});
Run Code Online (Sandbox Code Playgroud)
然后我在我的控制台中出错: …
我正在使用这个插件来创建图像缩放和图库,但我想缩放所有图像以适应容器(使用比率算法).
这是比率函数:
function scaleSize(maxW, maxH, currW, currH){
var ratio = currH / currW;
if(currW >= maxW && ratio <= 1){
currW = maxW;
currH = currW * ratio;
} else if(currH >= maxH){
currH = maxH;
currW = currH / ratio;
}
return [currW, currH];
}
Run Code Online (Sandbox Code Playgroud)
这就是画廊加载图片的方式:
var img = $('<img>').load(function(){
img.appendTo(a);
image_container.html(a);
}).attr('src', src).addClass(opts.big_image_class);
Run Code Online (Sandbox Code Playgroud)
我尝试过的:
var newSize = scaleSize(300, 320, $(".simpleLens-big-image").width(), $(".simpleLens-big-image").height());
var img = $('<img>').load(function(){
img.appendTo(a);
image_container.html(a);
}).attr('src', src).addClass(opts.big_image_class).width(newSize[0]).height(newSize[1]);
Run Code Online (Sandbox Code Playgroud)
但是scaleSize由于当前的宽度和高度尚未定义(dom中尚未存在图像),因此无法正常工作.
谢谢你的任何指示.
我想从我的asp.net mvc视图中的文本框中获取值.
<%: Html.TextBoxFor(m => m.UserName, new { @class = "flat" })%>
Run Code Online (Sandbox Code Playgroud) 我找到了这个答案,我试着遵循这个,但是当我开始服务时,它没有带给我任何工作.我无法理解的一件事是:`_timer = new Timer(10*60*1000); //每10分钟
我想每天晚上10点开始服务,我怎么能这样做?
我发现大多数答案window.onbeforeunload用于处理浏览器关闭.但它在刷新浏览器时也会采取行动.我只是想在浏览器关闭时不删除我的localStorage.
目前我正在自定义多选插件的多选下拉列表,这些是我将应用于自定义选择的行为:
(1), (2), (4) 我已经完成了。但是对于(3),我还没有想出任何解决方案。
这是多选的示例 json 字符串:
var _str = '{"10":{"0":"0","1":"DISPONIBILITES","2":"t","style":"font-weight: bold;"},"16":{"0":"0","1":"TRESORERIE NETTE","2":"t","style":"font-weight: bold;"},...."}}}';
Run Code Online (Sandbox Code Playgroud)
这是我创建的https://jsfiddle.net/skL589uu/7/。
如果这里有人能给我一些想法,那就太好了。