我试图通过CORS将表格数据从www.siteone.com发布到www.sitetwo.com.我的ajax代码是这样的:
<script>
$(document).ready(function(){
$("#submit").live('click',function() {
var url = "http://www.sitetwo.com/cors.php";
var data = $('#form').serialize();
jQuery.ajax({
url : url,
type: "POST",
data : $('#form').serialize(),
}).done(function(response){
alert(response);
}).fail(function(error){
console.log(error.statusText);
});
return false;
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
和cors.php文件www.sitetwo.com
如下:
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
echo "hai";
?>
Run Code Online (Sandbox Code Playgroud)
但仍然会抛出Access-control-Allow-Origin错误.抛出的错误是这样的:
XMLHttpRequest cannot load http://www.sitetwo.com/cors.php. Origin http://www.siteone.com is not allowed by Access-Control-Allow-Origin.
Run Code Online (Sandbox Code Playgroud)
我开始知道,通过只允许远程网站通过标头使用CORS,我们可以使用跨域请求.但是当我这样尝试时,会抛出错误.我在这里错过了什么吗?这是我的请求/响应标头:
Response Headers
Connection Keep-Alive
Content-Length 487
Content-Type text/html; charset=iso-8859-1
Date Fri, 23 Aug 2013 05:53:20 GMT
Keep-Alive timeout=15, max=99
Server Apache/2.2.15 (CentOS) …
Run Code Online (Sandbox Code Playgroud) 我在php中有一个数组
<?php
$array=array("a"=>"123","b"=>"234","c"=>"345");
array_shift($array);
//array("0"=>"234","1"=>"345");
?>
Run Code Online (Sandbox Code Playgroud)
如果我使用此功能,则键值会更改.我希望我的键值保持不变.如何在不影响数组键值的情况下删除第一个元素.我的回答应该是这样的
array("b"=>"234","c"=>"345");
Run Code Online (Sandbox Code Playgroud)
注意:请不要使用foreach(); 我想通过php中现有的数组函数来做到这一点
array_splice函数适用于上面的数组.但请考虑下面的数组
<?php
$array = Array
(
'39' => Array
(
'id' => '39',
'field_id' => '620'
),
'40' => Array
(
'id' => '40',
'field_id' => '620',
'default_value' => 'rrr',
));
array_splice($array, 0, 1);
print_r($array);
?>
Run Code Online (Sandbox Code Playgroud)
它的答案如下:
Array ( [0] => Array ( [id] => 40 [field_id] => 620 [default_value] => rrr ) )
Run Code Online (Sandbox Code Playgroud)
我可以知道原因吗?array_splice()只适用于单维数组吗?现在键值被重置......
我可以使用JsontoHtml库将JSON转换为HTML .现在,我需要将当前HTML转换为JSON,如此站点所示.查看代码时,我发现了以下脚本:
<script>
$(function(){
//HTML to JSON
$('#btn-render-json').click(function() {
//Set html output
$('#html-output').html( $('#html-input').val() );
//Process to JSON and format it for consumption
$('#html-json').html( FormatJSON(toTransform($('#html-output').children())) );
});
});
//Convert obj or array to transform
function toTransform(obj) {
var json;
if( obj.length > 1 )
{
json = [];
for(var i = 0; i < obj.length; i++)
json[json.length++] = ObjToTransform(obj[i]);
} else
json = ObjToTransform(obj);
return(json);
}
//Convert obj to transform
function ObjToTransform(obj)
{
//Get the DOM element
var …
Run Code Online (Sandbox Code Playgroud) 我有这种形式的内容
$content ="<p>This is a sample text where {123456} and {7894560} ['These are samples']{145789}</p>";
Run Code Online (Sandbox Code Playgroud)
我需要数组中花括号之间的所有值,如下所示:
array("0"=>"123456","1"=>"7894560","2"=>"145789")
Run Code Online (Sandbox Code Playgroud)
我试过这段代码:
<?php
preg_match_all("/\{.*}\/s", $content, $matches);
?>
Run Code Online (Sandbox Code Playgroud)
但我在这里得到的值从第一个大括号到内容中找到的最后一个.如何以上述格式获取数组?我知道我使用的模式是错误的.如何获得上面显示的所需输出?
我有以下示例:
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.testMethod = function() {
alert('hi');
}
});
Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@1.5.0" data-semver="1.5.0" src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.min.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="myCtrl">
{{testMethod()}}
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我在视图模板中只调用了一次该方法.但为什么要执行两次呢?
我在php中有两个数组,如代码所示
<?php
$a=array('0'=>array('500'=>'1','502'=>'2'));
$b=array('0'=>array('503'=>'3','504'=>'5'));
print_r(array_merge($a[0],$b[0]));
?>
Run Code Online (Sandbox Code Playgroud)
我需要合并两个数组.array_merge函数成功合并了其中两个,但键值发生了变化.我需要以下输出
Array
(
[0]=>Array(
[500] => 1
[502] => 2
[503] => 3
[504] => 5
)
)
Run Code Online (Sandbox Code Playgroud)
我可以在php中使用什么功能,以便在不更改键值的情况下获得以下输出?
使用history.pushState
,我们可以使用历史记录API更改当前网址.使用popstate
功能,我们可以回到上一页.但回过头来,我发现浏览器"点击此处继续"中的前向链接按钮被禁用.现在,使用历史记录,我需要访问该按钮的属性.
我们如何使用历史记录API访问转发按钮的网址?
我有一个多选chzn-select-deselect框.我想在选择特定值时一次选择多个值.我有以下HTML:
<select id="filter_list_dropdwn" class="inp direct_value_opp fl" multiple="multiple" name="data[value1][]">
<option value="1" parent_id="0"> parent1</option>
<option value="2" parent_id="1"> child1 of parent1</option>
<option value="3" parent_id="1"> child2 of parent1</option>
<option value="4" parent_id="3"> child of child3</option>
</select>
Run Code Online (Sandbox Code Playgroud)
如果我选择parent1,那么将自动选择它的子项.工作脚本是这样的:
$('#filter_list_dropdwn option:not(:selected)').live('click', function () {
unselected = $(this);
var parent_id = $(unselected).attr("value");
$('#filter_list_dropdwn option[parent_id=' + parent_id + ']').each(function (i, selected) {
$(this).prop('selected', false).click();
});
});
$('#filter_list_dropdwn option:selected').live('click', function () {
selected = $(this);
var parent_id = $(selected).attr("value");
$('#filter_list_dropdwn option[parent_id=' + parent_id + ']').each(function (i, selected) {
$(this).prop('selected', true).click(); …
Run Code Online (Sandbox Code Playgroud) 我有用于验证Amazon ses中的电子邮件地址的代码
<?php
$sesClient = SesClient::factory(array(
'key' => 'secret key',
'secret' => 'secret',
'profile' => 'user_name',
'region' => 'us-east-1'
));
$result = $sesClient->verifyEmailAddress(array('EmailAddress'=> $email));
?>
Run Code Online (Sandbox Code Playgroud)
$ result的输出是这样的:
object(Guzzle\Service\Resource\Model) {
[protected] structure => null
[protected] data => array()
}
Run Code Online (Sandbox Code Playgroud)
我实际上已经通过我指定的电子邮件ID验证了电子邮件.我的问题是,如何使用我收到的回复检查功能是否正常工作?在早期的亚马逊网络服务中,他们曾$result->is('Ok')
用于验证结果.我现在应该使用什么功能来检查该功能成功与失败的结果?
我已经检查了亚马逊链接,仍然无法找到成功响应的功能
这是我用于复选框的表单助手
<?php
echo $this->Form->input('name',array('type'=>'checkbox','options'=>$options));
?>
Run Code Online (Sandbox Code Playgroud)
和$ options数组如下:
[options] => Array
(
[58] => 58
[85] => 85
)
Run Code Online (Sandbox Code Playgroud)
但是我只得到一个包含两个值的复选框.如何获取每个值的复选框.
php ×7
javascript ×4
jquery ×4
arrays ×2
html ×2
amazon ×1
amazon-ses ×1
angularjs ×1
cakephp ×1
checkbox ×1
cors ×1
cross-domain ×1
function ×1
html5 ×1
json ×1
multi-select ×1
preg-match ×1
regex ×1