我从php url获取数组格式的ajax响应.如何在jQuery中提取数组响应值?供参考:
PHP数组是:
$response = array('msg' => 'Hello', 'html' => '<b>Good bye</b>');
Run Code Online (Sandbox Code Playgroud)
我在我的ajax响应中得到了$ response数组.即
var promo = "promo=45fdf4684sfd";
$.ajax({
type: "POST",
url: baseJsUrl + "/users/calc_discount",
data: promo,
success: function (msg) { // I am getting $response here as ajax response.
//alert(msg);
// Here I want to check whether response is in array format or not. if it is in array format, I want to extract msg here and want to use response array values.
}
});
Run Code Online (Sandbox Code Playgroud)
让我知道答案.谢谢.
我正在使用CakePHP进行开发,这是我的页面控制器:
<?php
class PagesController extends AppController
{
var $name = 'Pages';
var $helpers = array('Html', 'Session');
var $uses = array();
function display()
{
$path = func_get_args();
$count = count($path);
if (!$count) {
$this->redirect('/');
}
$page = $subpage = $title_for_layout = null;
if (!empty($path[0])) {
$page = $path[0];
}
if (!empty($path[1])) {
$subpage = $path[1];
}
if (!empty($path[$count - 1])) {
$title_for_layout = Inflector::humanize($path[$count - 1]);
}
$this->set(compact('page', 'subpage', 'title_for_layout'));
$this->render(implode('/', $path));
$this->loadModel('Curso', 2);
$select = $this->Curso->query("SELECT * FROM cursos ORDER …Run Code Online (Sandbox Code Playgroud) 当我在php中没有计算行数时,我确实喜欢这样
$sql=mysql_query("select * from users where username='$email'") or die("select error".mysql_query());
$no_rows=mysql_num_rows($sql);
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在蛋糕php中做到这一点,我的数据来自于此
[User] => Array
(
[first_name] => arjun
[last_name] => tyagi
[username] => arjun@gmail.com
[phone_no] => 9569908024
[mobile_no] => 9569908024
[state_id] => 2
[location_id] => 15
[password] => cffa41a028807034b54b5849d5f4d3ca7532e701
[confirm_password] => 12345
)
Run Code Online (Sandbox Code Playgroud) 我的员工表结构如下图所示

以下查询获得部门ID基于部门平均最高薪水
SELECT dep_id
FROM employee
GROUP BY dep_id
ORDER BY AVG( salary ) DESC
LIMIT 1
Run Code Online (Sandbox Code Playgroud)
产量
dep_id
2
Run Code Online (Sandbox Code Playgroud)
但我在更新查询中有问题
UPDATE employee
SET salary = salary +1000
where dep_id = (
SELECT dep_id
FROM employee
GROUP BY dep_id
ORDER BY AVG( salary ) DESC
LIMIT 1
)
Run Code Online (Sandbox Code Playgroud) $('#button').live('click', function () {
values_array = [];
$('.field').each(function () {
values_array.push = $(this).val();
});
$.ajax({
url: 'page.php',
data: {
array_a: values_array
},
type: 'POST',
success: function (data) {
$('#div').html(data);
}
});
});
//page.php
echo $_POST['array_a'] . "<br/>"; //The line break echos, but nothing else
Run Code Online (Sandbox Code Playgroud)
答:我是否需要迭代每个类$.each以创建一个正确的数组,和
B.)为什么不回复它?
我想更改宽度为41%宽度为的所有子div(parent div id = product_list)31%.
在jquery中是否有任何方法可以找到宽度为41%(仅在父div id = product_list下)的子div并将宽度更改为31%
注意:我无法设置代码子div id bocz那些随机更改的时间.
这是HTML代码
<div id="product_list" style="float:none;">
<div id="row_4fec46be9210e" style="margin-right: 5px; width:31%; float:left;">
<div id="row_4fec" style="margin-right: 5px; width:15%; float:left;"></div>
<div id="row_4fec" style="margin-right: 5px; width:16%; float:left;"></div>
<div>
<div id="row_4fec46be92339" style="margin-right: 5px; width:31%; float:left;"></div>
<div id="row_4fec46be92523" style="margin-right: 5px; width:31%; float:left;"></div>
<div id="row_4fec46be92523" style="margin-right: 5px; width:41%; float:left;"></div>
<div id="row_4fec46be92523" style="margin-right: 5px; width:41%; float:left;"></div>
</div>
Run Code Online (Sandbox Code Playgroud) ServiceController.php
public function admin_index() {
$services=$this->Service->find('all', array('order'=>'Service.id desc'));
$this->set('services', $services);
}
Run Code Online (Sandbox Code Playgroud)
admin_index.ctp(查看文件)
pr($services)
Array
(
[Service] => Array
(
[id] => 53
[user_id] => 65
[first_name] => client
)
[User] => Array
(
[id] => 65
[user_group_id] => 4
)
[SolutionType] => Array
(
[id] => 6
[solution_type] => face to face interaction
[status] => 0
)
[Service] => Array
(
[id] => 54
[user_id] => 66
[first_name] => client
)
[User] => Array
(
[id] => 66
[user_group_id] …Run Code Online (Sandbox Code Playgroud) php ×4
cakephp ×3
jquery ×3
ajax ×2
arrays ×2
javascript ×2
cakephp-1.3 ×1
cakephp-2.0 ×1
mysql ×1