用jquery ajax传递json对象(passing json object with jquery ajax)
试图回到这里的基础知识并通过ajax将JSON对象发送到我的php。 当我收到JSON错误时,我甚至无法访问该部分。 这是jquery代码:
jQuery(".deletebutton").on("click", function() { var employees = [ { "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName": "Jones" } ]; var dataString = JSON.stringify(employees); // Lets put our stringified json into a variable for posting var postArray = {json:dataString}; jQuery.ajax({ type: 'POST', url: 'index.php?option=com_recordings&task=deletevideos&format=raw', data: postArray, dataType: 'json', success: function(data){ if (data == "blah") alert(data); } }); });
我收到此错误(当我检查
errorThrown
):SyntaxError:JSON.parse:意外字符。 我用jsonlint.com查看它是有效的JSON。 我究竟做错了什么?Trying to go back to basics here and send a JSON object via ajax to my php. I can't even get to that part as I get a JSON error. Here is the jquery code:
jQuery(".deletebutton").on("click", function() { var employees = [ { "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName": "Jones" } ]; var dataString = JSON.stringify(employees); // Lets put our stringified json into a variable for posting var postArray = {json:dataString}; jQuery.ajax({ type: 'POST', url: 'index.php?option=com_recordings&task=deletevideos&format=raw', data: postArray, dataType: 'json', success: function(data){ if (data == "blah") alert(data); } }); });
I get this error (when I check
errorThrown
): SyntaxError: JSON.parse: unexpected character. I checked with jsonlint.com that it is valid JSON. What am I doing wrong?
原文:https://stackoverflow.com/questions/14265826
最满意答案
你可以做以下两件事之一:
- 给出一个固定的%宽度并将数学运算为中心:
position:absolute;width:60%;left:20%
(100%-60% = 40%
- >40% / 2 = 20%
)2。 使用
position:absolute;text-align:center;
定位divposition:absolute;text-align:center;
,并给出内部元素position:relative;display:inline-block;
You can do one of two things:
- give a fixed % width and do the math to center:
position:absolute;width:60%;left:20%
(100%-60% = 40%
-->40% / 2 = 20%
)2 . position the div using
position:absolute;text-align:center;
, and give the inner elementsposition:relative;display:inline-block;
相关问答
更多-
您的问题可能会解决,如果你给你的div一个固定的宽度,如下所示: div#thing { position: absolute; top: 0px; z-index: 2; width:400px; margin-left:-200px; left:50%; } Your problem may be solved if you give your div a fixed width, as follows: div#thing { position ...
-
由于顶部和左侧偏移量为37%,如果视口太小,文本将显示在屏幕外。 更简单的解决方案是简单地将.parent元素设置为table显示,然后将.child元素设置为以水平和垂直对齐的内容显示为table-cell : .parent { display: table; height: 100%; width: 100%; } .child { display: table-cell; text-align: center; vertical-align: mid ...
-
如果我理解你的问题,那么它将如下工作。 你可以通过三种方式来完成。 No1 - 使用位置。 将宽度100%应用于按钮父div,并将按钮样式应用于下面。 .buy-btn{ display: inline-block; /* Display inline block */ text-align: center; /* For button text center */ position: absolute; /* Position abs ...
-
所以问题似乎是图像是一个SVG,IE9在SVG图像方面有奇怪的缩放行为。 解决方案是添加Polyfill,如果检测到任何IE版本,则用后备PNG替换SVG。 So the issue seemed to be that the image was an SVG and IE9 has strange scaling behavior when it comes to SVG images. The solution was to add a Polyfill if any IE version is det ...
-
我认为没有绝对定位你就做不到。 下面的代码可以帮助你。 #lightgallery a { width: calc(100% / 3); height: 240px; text-decoration: none; position: relative; } a[href*="youtu"]::before { font-family: 'FontAwesome'; content: "\f144"; font-size: 2.5em; ...
-
中心绝对定位(center a absolute positioned)[2023-07-13]
你可以做以下两件事之一: 给出一个固定的%宽度并将数学运算为中心: position:absolute;width:60%;left:20% ( 100%-60% = 40% - > 40% / 2 = 20% ) 2。 使用position:absolute;text-align:center;定位div position:absolute;text-align:center; ,并给出内部元素position:relative;display:inline-block; You can do one o ... -
在你的风格中添加这个css .slideshow img {width: 100%; opacity: 0;} .slideshow .images {float:left; 宽度:100;} add this css in your style .slideshow img {width: 100%; opacity: 0;} .slideshow .images {float:left; width:100;}
-
添加left:0; right:0 left:0; right:0 (这将删除绝对定位div的默认值),然后margin:0 auto将其带到中心。 .fadein img { position:absolute; left:0; right:0; top:0; margin:0 auto} DEMO Add left:0; right:0 (this removes the default values of absolute positioned div) and then margin:0 auto ...
-
我不确定为什么你需要绝对定位孩子。 这是你想要实现的目标: http : //jsfiddle.net/k65pxydx ? .myAbsoluteContainer { text-align: center; /* Centers the elements horizontally */ } .myAbsoluteChildElement { display: inline-block; vertical-align: middle; /* Centers the elements ...
-
如何在绝对定位元素上从右转换到中心?(how to do transition from right to center on absolute positioned element?)[2023-04-07]
你可以用CSS3制作这个动画,这很简单。 在悬停时,框的不透明度会发生变化,文本会向左移动,因此,CSS: .customoverlay { position: relative; display: block; width: 100%; height: 300px; } .customoverlay img { margin: 0; padding: 0; } .customoverlay .inneroverlaybox { position: a ...