所以我有这个按钮,它会在表格中添加一个新行,但我的问题是它.new_participant_form
在append方法发生后不再监听click事件.
单击"添加新条目",然后单击"表单"名称.
$('#add_new_participant').click(function() {
var first_name = $('#f_name_participant').val();
var last_name = $('#l_name_participant').val();
var role = $('#new_participant_role option:selected').text();
var email = $('#email_participant').val();
$('#registered_participants').append('<tr><td><a href="#" class="new_participant_form">Participant Registration</a></td><td>'+first_name+ ' '+last_name+'</td><td>'+role+'</td><td>0% done</td></tr>');
});
$('.new_participant_form').click(function() {
var $td = $(this).closest('tr').children('td');
var part_name = $td.eq(1).text();
alert(part_name);
});
});
Run Code Online (Sandbox Code Playgroud)
<table id="registered_participants" class="tablesorter">
<thead>
<tr>
<th>Form</th>
<th>Name</th>
<th>Role</th>
<th>Progress </th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#" class="new_participant_form">Participant Registration</a></td>
<td>Smith Johnson</td>
<td>Parent</td>
<td>60% done</td>
</tr>
</tbody>
</table>
<button id="add_new_participant"></span>Add New Entry</button>
Run Code Online (Sandbox Code Playgroud) 复制此表:User_Posts
ID | Upvotes | Downvotes | CAT |
___________________________________
42134 | 5 | 3 | Blogs|
------------------------------------
12342 | 7 | 1 | Blogs|
-------------------------------------
19344 | 6 | 2 | Blogs|
------------------------------------
Run Code Online (Sandbox Code Playgroud)
我需要在其类别中获得项目的排名.因此ID:19344将排名第2位,有4个赞成票,12342位有6个赞成票.排名由(upvotes-downvotes)计数在其类别中确定.
所以我写了这个MySQL查询.
SELECT rank FROM (SELECT *, @rownum:=@rownum + 1 AS rank
FROM User_Posts where CAT= 'Blogs' order by
(Upvotes-Downvotes) DESC) d,
(SELECT @rownum:=0) t2 WHERE POST_ID = '19344'
Run Code Online (Sandbox Code Playgroud)
直接在mysql中运行时返回给我(Rank = 2).这是正确的结果
但是,当我尝试通过代码点火器的查询构建器构建它时,我得到了
$table = 'User_Posts';
$CAT= 'Blogs';
$POST_ID = '19344';
$sql = "SELECT …
Run Code Online (Sandbox Code Playgroud) 我正在使用PHP 的请求库(http://requests.ryanmccue.info/).
我安装了composer并添加了以下Json配置composer.json
:
{
"require": {
"rmccue/requests": ">=1.0"
},
"autoload": {
"psr-0":{"Requests" : "library/"}
}
}
Run Code Online (Sandbox Code Playgroud)
所以在我的控制器中我试图通过库运行请求,我得到:
public function index()
{
Requests::register_autoloader();
$headers = array('Accept' => 'application/json');
$options = array('auth' => array('user', 'pass'));
$request = Requests::get('https://api.github.com/gists', $headers, $options);
var_dump($request->status_code);
// int(200)
var_dump($request->headers['content-type']);
// string(31) "application/json; charset=utf-8"
var_dump($request->body);
}
Run Code Online (Sandbox Code Playgroud)
:第34行的../application/controllers/test.php中找不到"请求"类
当我点击菜单中的元素时,我正在尝试添加一个类[active].然后在单击菜单中的新项目并将[active]类添加到其中时删除该类[active].
我试过了 $(this).removeClass("active").addClass("active");
$(this).toggleClass("active");
Run Code Online (Sandbox Code Playgroud)
基本上我正在尝试使用hover()函数,但点击均匀.
编辑:修正了HTML
<ul class="menu">
<li><span>Three</li>
<li><span>Two</li>
<li><span>One</li>
</ul>
Run Code Online (Sandbox Code Playgroud) 我正在使用PHP与CodeIgniter框架.我读了一些文章说明使用try/catch方法是不好的做法.
我理解在发生潜在错误时使用登录开发并让实际错误发生然后使用它进行记录 log_message('level', 'message')
但是在部署时,您希望抑制并处理出现的任何错误.我应该使用try/catch块,例如...
try {
$this->data['important'] = $this->Test_Model->do_something($data);
if(empty(data['important'])) {
throw new Exception('no data returned');
}
catch (Exception $e) {
//alert the user then kill the process
var_dump($e->getMessage());
}
Run Code Online (Sandbox Code Playgroud)
当我正确使用try/catch时,我很困惑.
我希望将一个数组传递给一个函数(你能告诉我我是否在正确的轨道上?)
然后在函数中我希望循环遍历数组中的值,并将每个值附加到HTML中的以下LI元素中
这是我到目前为止用户将在他想要传递的URL值中编码:
var arrValues = ['http://imgur.com/gallery/L4CmrUt', 'http://imgur.com/gallery/VQEsGHz'];
calculate_image(arrValues);
function calculate_image(arrValues) {
// Loop over each value in the array.
var jList = $('.thumb').find('href');
$.each(arrValues, function(intIndex, objValue) {
// Create a new LI HTML element out of the
// current value (in the iteration) and then
// add this value to the list.
jList.append($(+ objValue +));
});
}
}
Run Code Online (Sandbox Code Playgroud)
HTML
<li>
<a class="thumb" href="" title="Title #13"><img src="" alt="Title #13" /></a>
<div class="caption">
<div class="download">
<a href="">Download Original</a>
</div>
<div class="image-title">Title …
Run Code Online (Sandbox Code Playgroud) 我将以下内容添加到我的functions.php文件中:
add_action('wp_ajax_send_email', 'send_email_callback');
add_action('wp_ajax_nopriv_send_email', 'send_email_callback');
Run Code Online (Sandbox Code Playgroud)
所以我添加了以下回调函数:
send_email_callback()
{
//do some processing
echo json_encode(array('response'=>'Ya man it worked.'));
//return control back to *-ajax.php
}
Run Code Online (Sandbox Code Playgroud)
这是我的javascript返回的内容:
{"response":"Ya man it worked."}0
Run Code Online (Sandbox Code Playgroud)
所以当它到达$ .parseJSON(msg)行时,我得到Uncaught SyntaxError:意外的数字.
var request = $.ajax({
url: "/wp-admin/admin-ajax.php",
method: "POST",
data: { action : 'send_email', P : container },
dataType: "html"
});
request.done(function( msg ) {
var obj = $.parseJSON( msg );
console.log(obj.response);
});
request.fail(function( jqXHR, textStatus ) {
alert( "Request failed: " + textStatus );
});
});
Run Code Online (Sandbox Code Playgroud)
那么0来自哪里?admin-ajax.php 它在第97行说:
// …
Run Code Online (Sandbox Code Playgroud) 我有一个网络服务器,某些用户一直在使用自动脚本检索我的图像.我希望将它们重定向到错误页面,或者只有当它是一个CURL请求时才给它们一个无效的图像.
我的图像存在http://example.com/images/AIDd232320233.png
,是否有一些我可以用.htaccess将它路由到我的控制器索引函数,我可以检查它是否是一个真实的请求?
我的另一个问题是,我如何检查浏览器标题以区分最可能的真实和使用cURL请求?
使用此Jquery AJAX方法的新手.所以我正在使用Jquery进行AJAX调用,在我的PHP脚本中,我在从数据库中检查条件为真,然后传入我的数据字符串并绑定变量,然后执行该查询.脚本和数据库插入都正常工作.
我的问题是,如何从我的PHP脚本返回时在我的AJAX调用中显示错误消息?
JS
$.ajax({
type: "POST",
url: 'submit_form.php',
data: dataString,
error: function() { alert('Error'); },
success: function() { alert('Success'); }
});
Run Code Online (Sandbox Code Playgroud)
if ( count of rows in db < x )
{
return false;
exit();
}
Run Code Online (Sandbox Code Playgroud)
如果这个条件为真,我想停止执行我的脚本并在我的AJAX函数中执行错误条件.
elseif ($stmt = $mysqli->prepare("INSERT INTO blah (stuff, morestuff) values (?, ?)")) {
/* Bind our params */
$stmt->bind_param("ss", $param1, $param1);
/* Set our params */
$param1= $_POST["name"];
$param2= $_POST["email"];
/* Execute the prepared Statement */
$stmt->execute();
/* Close the statement */ …
Run Code Online (Sandbox Code Playgroud) 我是我页面上的几个Jquery UI进度条小部件实例.
我遇到的问题是它只加载第一个值,并模拟每个条形图,而不是循环遍历页面上的所有条形并获取唯一值.任何人都可以解释为什么每个函数没有正确循环这些值?
添加了一个小提琴:http://jsfiddle.net/Uy9cA/25/
<div class="progress_bar" value="20"><div class="progress-label">Loading...</div></div> <div class="progress_bar" value="40"><div class="progress-label">Loading...</div></div>
Run Code Online (Sandbox Code Playgroud)
$(function() {
$('.progress_bar').each(function() {
var progressbar = $( ".progress_bar" ),
progressLabel = $( ".progress-label" ),
progressvalue = $(".progress_bar").attr('value');
console.log(progressvalue);
progressbar.progressbar({
value: false,
change: function() {
progressLabel.text( progressbar.progressbar( "value" ) + "% Complete" );
},
complete: function() {
progressLabel.text( "Complete!" );
}
});
function progress() {
var val = progressbar.progressbar( "value" ) || 0;
progressbar.progressbar( "value", val + 1 )
.removeClass("beginning middle end")
.addClass(val < …
Run Code Online (Sandbox Code Playgroud)