我可能做了一些非常简单的错误,但是当我尝试创建一个目录(使用插入的变量作为最后一个文件夹名称执行)时,我收到错误:
警告:mkdir()[function.mkdir]:/ home/blah/blah中没有这样的文件或目录
用代码:
if (!is_dir("images/listing-images/rent/'.$insertID.")) {
//make new directory with unique id
mkdir("images/listing-images/rent/'.$insertID.");
}
Run Code Online (Sandbox Code Playgroud)
当然目录不存在..我正在尝试现在制作它?困惑!
即时通过phonegap构建应用程序,带有地理定位按钮.
如果用户第一次拒绝地理定位权限,当他们再次点击地理定位按钮时,如何再次请求权限?
我目前的代码结构是:
function getLocation() {
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, positionError);
} else {
hideLoadingDiv()
showError('Geolocation is not supported by this device')
}
}
function positionError() {
hideLoadingDiv()
showError('Geolocation is not enabled. Please enable to use this feature')
}
Run Code Online (Sandbox Code Playgroud) 我需要在-100和变量'max_top'之间生成一个随机数(总是一个正数,最多约为40).这个数字需要既可以是负数也可以是正数.
我怎样才能做到这一点?
我有一个页面显示有关属性的信息,基于url中的唯一ID,在mysql数据库中搜索该ID,从该行获取所有信息等,真的很标准.
我想知道是否/如何为每个数据库行"创建"一个html页面,因为我认为这对SEO更好?有多个关键字而不是一个动态页面?
我的属性通过网站上的表单/上传系统添加到数据库中,我想在上传时创建页面可能是最简单的,但我愿意接受建议!
我有一个有两个字段的表格; 手机号码.和电话号码.
必须填写至少一个字段,但两者都可以填写.
如果没有填充错误,我需要jquery validate来抛出错误.
我已经实现了这个:
rules: {
mobile:{
required: {
depends: function(element) {
return $("#regTelephone").val() === '';
}
}
},
telephone:{
required: {
depends: function(element) {
return $("#regMobile").val() === '';
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果只有一个字段为空,则此字段仍然会获得"有效"类,我不希望这样,因为我的有效css具有绿色边框(因此空字段仍然为绿色边框)
所以:我如何获得空的字段(提供另一个有值)以获得无效的类,因此得到绿色边框?
我正在将输入动态添加到我的页面中,因此需要使用它.on来附加事件.
我正在尝试将change事件附加到a type="file" input,但它只是不起作用.
我试过两种方法,第一种:
$('.container').on('change', '.file-input-hidden' , function(){
Run Code Online (Sandbox Code Playgroud)
输入有一个类file-input-hidden.
第二个:
$('.container').on('change', 'input[type="file"]' , function(){
Run Code Online (Sandbox Code Playgroud)
但是当用文件选择/更改文件时,都不会激活该功能input.
出了什么问题?
编辑:
在这里查看页面:链接
和js:
$('.container').on('click', '.file-browse' , function(){
var thisone = $(this).attr('id');
$('input[name="input-'+ thisone+'"]').click();
});
$('.file-input-hidden').on('change', function(){
var thetext = $(this).val();
var thetextsplit = thetext.split('\\').pop();
var thisone = $(this).attr('name').split('-').pop();
if($('.file-info').text() == thetextsplit){
alert('you have already selected this file');
$(this).replaceWith( $(this).val('').clone( true ) );
}
else{
$('#info-'+ thisone).text(thetextsplit);
$('#clear-'+ thisone).fadeIn(100);
var emptyinputs = $('.file-info:empty').length;
if(emptyinputs …Run Code Online (Sandbox Code Playgroud) 我需要存储(许多)对象或数据数组,它们需要具有以下条件:
我需要能够轻松地将一组新数据添加到现有数据中
我需要能够按轻松添加的日期/时间对数据进行排序(按条目推送到它的时间顺序排列的数组)
我需要能够使用引用(整数或字符串)轻松获取条目。这很重要,目前我必须执行 $.each() 来循环我的数据,直到找到我想要的条目。
我曾尝试使用如下结构:
saved_info = {
1001: {//all my data for ref 1001},
1002: {//all my data for ref 1002}
}
Run Code Online (Sandbox Code Playgroud)
这给了我想要能够轻松获取信息的参考:
info = saved_info[1001];
Run Code Online (Sandbox Code Playgroud)
但是,我使用的参考编号不是按顺序排列的 - 我使用给我的参考(它是唯一标识符),因此对象不是按添加/保存/推送项目的时间顺序排列的。
我遍历一个运行ajax请求的数组.我需要按顺序发生请求,所以我可以获取最后一个请求并在成功时运行一个函数.
目前我正在运行(简化):
$.each(array, function(i, item){
ajax_request(item.id, item.title, i);
})
function ajax_request(id, title, i){
$.ajax({
async: false,
url: 'url here',
success: function(){
if(i == array.length-1){
// run function here as its the last item in array
}
}
})
}
Run Code Online (Sandbox Code Playgroud)
但是,使用async:false会使应用程序无响应/慢.但是,没有async:false有时其中一个请求会挂起一点,并在最后发送的ajax请求返回后实际返回.
如何在不使用async的情况下实现这一点:false?
我正在尝试使用ajax和FormData上传图像
我的HTML看起来像:
<form id="profile-photo-form">
<input type="file" id="profile-photo-choose" name="photo_path" accept="image/*">
</form>
Run Code Online (Sandbox Code Playgroud)
和js函数调用文件选择器的更改:
var form_data = new FormData($('#profile-photo-form')[0]);
$.ajax({
type: 'POST',
url: api_url,
data:form_data,
headers:{
'X-CVL-Auth': cookie
},
success: function(result){
Run Code Online (Sandbox Code Playgroud)
但我得到一个javascript错误:
TypeError: Can only call DOMFormData.append on instances of DOMFormData
Run Code Online (Sandbox Code Playgroud)
这是在ios上加载的html应用程序(phonegap)
我有一个数组,我做了一些事情,但现在我试图在'页面'之间划分它(更像幻灯片).
我使用该.each()方法遍历它,调用这个冗长的代码来将信息放在正确的页面上(每页只有5个项目,至少现在至少).
有没有办法简化这段代码?
理想情况下它可以无限地继续下去:
if (index > 0 && index <= 5) {
var page = $('#librarian-page-gallery-1');
} else if (index > 5 && index <= 10) {
var page = $('#librarian-page-gallery-2');
} else if (index > 10 && index <= 15) {
var page = $('#librarian-page-gallery-3');
} else if (index > 15 && index <= 20) {
var page = $('#librarian-page-gallery-4');
} else if (index > 20 && index <= 25) {
var page = $('#librarian-page-gallery-5');
} …Run Code Online (Sandbox Code Playgroud)