这可能是我对AJAX如何运行的误解,但我有一种情况,即在GET请求实际完成之前$.get调用callback(.always()).至少,这就是它的样子.
代码
var apiRequest = 'some/url/';
// fetch list of video embed codes
$.get( apiRequest, function( embed_codes ) {
// added this per Explosion Pills' answer
var jqxhrs = [];
// for each embed code, get video details (name, duration, etc.)
for ( var i = 0; i < embed_codes.length; i++ ) {
var videoDetailsRequest = '/v2/assets/' + embed_codes[i];
//..declare vars..
// fetch video details
var jqxhr = $.get( videoDetailsRequest, function( video ) {
// build …Run Code Online (Sandbox Code Playgroud) 我的PHP文件中有以下jQuery代码(2010年1月19日编辑@ 10:40 MST):
<?php
$count = 0;
foreach($attachments as $attachment) :
echo '<script type="text/javascript">
$(\'#a_'.$count.'\').click(function() {
$(\'#d_'.$count.'\').show(200);
});
// if "no" is clicked
$(\'#d_'.$count.' .no\').click(function() {
$(\'#d_'.$count.'\').hide(200);
});
// if "yes" is clicked
$(\'#d_'.$count.' .yes\').click(function() {
$(\'#d_'.$count.'\').hide(200);
// update database table -- this is why I need the script inside the for loop!
var jsonURL = \'http://path/to/update_db_script.php\';
$.getJSON(jsonURL, {\'post_id\' : '.$attachment->ID.'}, function(data) {
alert(\'Thank you. Your approval was received.\');
});
$(\'#a_'.$count.'\').replaceWith(\'<span>Approved</span>\');
});
</script>';
echo '<li>';
if($attachment->post_excerpt == 'approved') …Run Code Online (Sandbox Code Playgroud) 我按照这里的说明在我的Mac上配置Apache,PHP和MySQL(运行Sierra 10.12.4)并使一切正常.然后我使用迁移助手将所有内容复制到新Mac(Mac#2)以供其他开发人员使用.首次登录时,我打开了Chrome并访问过localhost.我事先没有对Mac#2做任何改动.
在Mac#2上,当我访问localhostChrome时,我得到了一个ERR_CONNECTION_REFUSED (无法访问此站点:localhost拒绝连接).一些挖掘引导我在Apple Stack Exchange上进行此问答,所以我在终端中尝试了以下内容:
ping 127.0.0.1 (成功;即"从127.0.0.1开始的64个字节...")ping localhost (成功)ping myvirtualhost.dev (成功)然后我试图运行apachectl configtest,这引发了以下错误:
/usr/local/bin/apachectl: line 79: 1132 Illegal instruction: 4 $HTTPD -t好的,怎么样sudo apachectl -k restart?不,同样的错误:
/usr/local/bin/apachectl: line 79: 1170 Illegal instruction: 4 $HTTPD "$@"省略该-k标志会引发相同的错误,但最后一个字符有点不同:
/usr/local/bin/apachectl: line 79: 1184 Illegal instruction: 4 $HTTPD -k $ARGV我不能停止,启动,重启或真正用Apache做任何事情.谷歌搜索错误并没有带来太大的影响.我已经尝试 …
我正在构建一个价格估算器表单,它使用jQuery来操作选择菜单.基本上,当选择新数量时,每个选择菜单中每个选项的值乘以每单位价格,并向用户显示新价格.
我想要做的是从PHP文件中提取每单位价格,该文件将这些价格存储在一系列数组中; 例如:
<?php
// prices.php
$colorPrices = array(2.339,3.195,6.537,2.614,2.614,1.759);
$json = json_encode($colorPrices);
echo $json;
?>
Run Code Online (Sandbox Code Playgroud)
保持阵列分离将使我的jQuery更清洁,并使更容易更新定价.
在我的jQuery文件中,它计算总价格,我正在读这样的JSON:
$.getJSON('prices.php',function(data) {
var colorArray = data;
})
Run Code Online (Sandbox Code Playgroud)
在这一点上,colorArray是一个对象,所以它对这个jQuery并不好玩:
// whenever a new COLOR is chosen, step through colorArray and multiply by the currently selected QUANTITY
$('#colors option').each(function(i){
$(this).attr('label',qty * colorArray[i]);
});
Run Code Online (Sandbox Code Playgroud)
我的想法是,如果我可以将colorArray转换为数组,我可以遍历其内容.现在,当我选择一种新颜色时没有任何反应.
我是关闭还是无能为力?
jquery ×3
ajax ×1
apache ×1
asynchronous ×1
httpd.conf ×1
javascript ×1
json ×1
localhost ×1
macos ×1
php ×1