我想在内容区域的主页上创建一个新闻订阅框,为此我创建了一个CMS页面,我在新闻订阅文件中放置的其他代码也可以调用.
我想这样称呼它:
<?php echo $this->getLayout()->createBlock('newsletter/subscribe')->setTemplate('newsletter/subscribe.phtml')->toHtml(); ?>
Run Code Online (Sandbox Code Playgroud)
但它没有显示出来.
为什么?
这是我的POST数据代码:
<?php
$data = array("account" => "1234", "dob" => "30051987", "site" => "mytestsite.com");
$data_string = json_encode($data);
$url = 'http://mydomain.com/curl.php';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
curl_close($ch);
$json_result = json_decode($result, true);
?>
<p>Your confirmation number is: <strong><?php echo $json_result['ConfirmationCode']; ?></strong></p>
Run Code Online (Sandbox Code Playgroud)
而域/服务器curl.php文件代码如下:
<?php
// header
header("content-type: application/json");
if($_POST):
echo json_encode(array('ConfirmationCode' => 'somecode'));
else:
echo json_encode(array('ConfirmationCode' => 'none'));
endif;
?> …Run Code Online (Sandbox Code Playgroud) var storeSettings = [];
obj.find(o_widgetClass).each(function(){
var storeSettingsStr = {};
storeSettingsStr['id'] = $(this).attr('id');
storeSettingsStr['style'] = $(this).attr('data-widget-attstyle');
storeSettingsStr['title'] = $(this).children('header').children('h2').text();
storeSettingsStr['hidden'] = ($(this).is(':hidden') ? 1 : 0);
storeSettingsStr['collapsed'] = ($(this).hasClass('powerwidget-collapsed') ? 1 : 0);
storeSettings.push(storeSettingsStr);
});
var storeSettingsObj = JSON.stringify( {'widget':storeSettings} );
/* Place it in the storage(only if needed) */
if(getKeySettings != storeSettingsObj){
//alert(storeSettingsObj);
var memberfilter = new Array();
memberfilter[0] = "id";
memberfilter[1] = "style";
var jsonText = JSON.stringify(storeSettings, memberfilter);
alert(jsonText);
// it gives this result
[{"id":"widget1"},{"id":"widget3","style":"black"},{"id":"widget4"},{"id":"widget5"},{"id":"widget2","style":"black"},{"id":"widget6"},{"id":"widget7"},{"id":"widget9"},{"id":"widget8"},{"id":"widget10"},{"id":"widget12"},{"id":"widget13"},{"id":"widget11"},{"id":"widget14"}]
Run Code Online (Sandbox Code Playgroud)
现在我如何通过 jquery ajax 发送它?我正在尝试使用下面提到的代码 …
获取iframe的内容后,将其过滤以获取具有自定义属性的第一个元素data-type = filled.但是我无法在该特定元素上应用类.
这是我的代码:
var clicked_content = event.target.outerHTML, // gives the content being clicked
content = $(clicked_content).find("*[data-type='filled']:first").andSelf().html(); // this gives me the required content
// this was supposed to add a class to particular element
content.parent.addClass("highlight");
Run Code Online (Sandbox Code Playgroud)
我也试过这样做:
$(event.target).children().find("*[data-type='filled']:first").andSelf().addClass('highlight');
Run Code Online (Sandbox Code Playgroud)