Ajax:每点击一次,就会发送一个ajax请求,控制台会显示服务器发送的文本。
“服务器发送事件”:它在随机时间向控制台发送文本
如果我只使用 ajax,我会从服务器收到数据。但是如果我同时使用这两种方法,我没有从服务器接收数据以响应 ajax 请求,但仍然收到响应“服务器发送事件”的消息。我什至没有收到来自 ajax 请求的失败消息。有人可以解释一下吗?
客户
var evtSource = new EventSource("config/addRemoveEvent.php");
evtSource.onmessage = function(e) {
//var newElement = document.createElement("li");
console.log("listening: "+ e.data);
//newElement.innerHTML = "message: " + e.data;
//eventList.appendChild(newElement);
}
var data = {
'action':'Initiate brief calendar',
'selectedMonth': month,
'selectedYear': year
};
var $request = $.ajax({
type: "GET",
dataType: "text",
url: "config/addRemoveEvent.php",
data: data,
beforeSend: function(){
console.log('start sending request');
}
});
$request.fail(function(){
console.log('fail');
});
$request.done(function(data){
// change bg color of the cells that contain events;
console.log(data);
}); …Run Code Online (Sandbox Code Playgroud) 使用名为cropper的jQuery插件,我能够将裁剪后的图像检索为blob对象.现在我需要将这个blob对象保存为我服务器上的文件.代码是:
$('#image').cropper('getCroppedCanvas').toBlob(function (blob) {
var formData = new FormData();
formData.append('croppedImage', blob);
formData.append('form_key', window.FORM_KEY);
$.ajax('/upload.php', {
method: "POST",
data: formData,
processData: false,
contentType: false,
success: function (data) {
console.log(data);
},
error: function (data) {
console.log(data);
}
});
});
Run Code Online (Sandbox Code Playgroud)
这是我的upload.php:
<?php
$blob = $_POST['croppedImage'];
//return $blob;
file_put_contents('/media/crop_products/test.png', $blob);
?>
Run Code Online (Sandbox Code Playgroud)
它不是保存在服务器上.我在这里做什么?此请求来自magento的管理页面.
我正在使用vagrant设置新的Ubuntu计算机。通过配置,我需要创建一个新的postgres用户。目前,我正在使用:
sudo su postgres
createuser -P myuser
Run Code Online (Sandbox Code Playgroud)
不幸的是,调配失败,因为提示需要输入密码(-P标志)。
有没有办法将密码传递给createuserlike createuser myuser --password test或echo test | createuser -P myuser?
$emailFields = array(
array(
'name' => 'comments',
'type' => 'html',
'content' => "ahfsd\jfh/sf's askghaskg sadf"
),
);
echo json_encode($emailFields);
Run Code Online (Sandbox Code Playgroud)
打印的是
[{
"name": "comments",
"type": "html",
"content": "ahfsd\\jfh/sf's askghaskg sadf"
}]
Run Code Online (Sandbox Code Playgroud)
为什么json_encode无法转义'?
我需要将一些内容数据提供给我的控制器:
state('admin.businesses.employees.all', {
resolve: {
executorsListTitle: 'All employees',
executorsEmptyListMessage: 'Add the first employee'
},
url: '/all',
controller: 'ExecutorsController',
templateUrl: 'templates/admin/executors/index.html'
})
Run Code Online (Sandbox Code Playgroud)
和一个控制器代码:
module.controller(
'ExecutorsController',
[
'$scope', '$rootScope', '$state',
'$stateParams', '$modal', 'executorsListTitle',
'executorsEmptyListMessage', 'Executor',
function($scope, $rootScope, $state, $stateParams, $modal, executorsListTitle, executorsEmptyListMessage, Executor) {
// Some code
}
)
Run Code Online (Sandbox Code Playgroud)
但是当我试图进入这种状态时,我无法做到这一点 - 按下按钮就什么都不做; 如果我从状态描述中删除了解决方案,那就很好.我做错了什么?谢谢!
我有这个功能正在工作:
$('#buttFurniture').click(onFilterCLick);
Run Code Online (Sandbox Code Playgroud)
但后来我决定在函数中添加一些参数并停止工作:
$('#buttFurniture').click(onFilterCLick(arrOutput, arrFurniture));
Run Code Online (Sandbox Code Playgroud)
全功能:
function onFilterCLick(arrFull,arrCurrent) {
$('#buttFurniture').css("background-color", "#F1F1F1");
$('#buttCars').css("background-color", "#F1F1F1");
$('#buttGames').css("background-color", "#F1F1F1");
$('#buttFurniture').css("color", "black");
$('#buttCars').css("color", "black");
$('#buttGames').css("color", "black");
$(this).css("background-color", "#656565");
$(this).css("color", "white");
if (jQuery.inArray(arrCurrent[0], arrFull)) {
console.log("asdasd");
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用bootstrap框架,我希望有3个图像,如下面的jsfiddle链接所示,当窗口大小更改/监视器大小太小而无法显示完整大小的图像时,在响应庄园中执行操作.重要的是图像保持在同一条线上(如果可能),两者之间没有间距.
<img src="http://via.placeholder.com/660x160.png"><img src="http://via.placeholder.com/350x160.png"><img src="http://via.placeholder.com/350x160.png">
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在尝试构建一个应用程序,该应用程序生成一个加密密钥,然后将其直接放置在 C++ 应用程序的代码中以对其进行解密。
我对如何将 PHP 中的字符串转换为 C++ 中使用的格式感到困惑。
例如,在这里看看这个问题: XTEA 加密在 PHP 中,解密在 C 中
dschulz的答案是如何得到字符串的
annoying monkey
Run Code Online (Sandbox Code Playgroud)
到
uint32_t key[4] = {0x6f6e6e61, 0x676e6979, 0x6e6f6d20, 0x0079656b };
Run Code Online (Sandbox Code Playgroud)
以及如何在 PHP 中完成此操作,以便以该格式打印该行?
我试过将字符串转换为十六进制并附加 0x 但它不起作用,任何帮助将不胜感激。
我在我的小项目中有一个流动来显示两个不同列的数量和日期.需要注意的一点是,它将多个值存储在由(,)分隔的列中:
$apaidArray = explode(',', $apaid);
$daterArray = explode(',', $dater);
for ( $i = 0; $i < count($apaidArray); $i++ ){
echo $apaidArray[$i].' repaid on ' .$daterArray[$i].'<br>';
}
Run Code Online (Sandbox Code Playgroud)
由于最初在还款金额之前放置的(,)结果,如果只有两个条目进入db,则会显示以下内容:
apaid = , 80, 20
dater = , 12.07.2017, 13.07.2017
Run Code Online (Sandbox Code Playgroud)
结果如下:
repaid on
80 repaid on 12.07.2017
20 repaid on 13.07.2017
Run Code Online (Sandbox Code Playgroud)
所以我的问题是有没有一种方法可以在显示结果之前删除(,),只有当它是该列中的第一个值时才会产生结果:
80 repaid on 12.07.2017
20 repaid on 13.07.2017
Run Code Online (Sandbox Code Playgroud)
任何帮助是极大的赞赏.
我写了这个PHP代码:
<?php
$host = "localhost";
$username = "user";
$password = "pass";
$db = "database";
mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
mysql_close;
$lines = explode("\n", file_get_contents("textfile.txt"));
foreach($lines as $pass => $password)
{
$string = trim($password);
$md5hash = md5($string);
$sha1hash = sha1($string);
$res = mysql_query("INSERT INTO `md5` VALUES ('', '$password', '$md5hash', '$sha1hash')") or die(mysql_error());
}
?>
Run Code Online (Sandbox Code Playgroud)
但我还是得到了
允许的内存大小为734003200字节耗尽
致命错误:内存不足(已分配262144)(尝试分配15696126973字节)
我尝试了很多解决方案,但这没有帮助!有没有办法通过更改或添加PHP代码来解决这个问题..
谢谢
php ×6
html ×2
javascript ×2
jquery ×2
mysql ×2
ajax ×1
angularjs ×1
arrays ×1
blob ×1
c++ ×1
encryption ×1
json ×1
magento ×1
postgresql ×1
responsive ×1
vagrant ×1