HTTP 请求按预期工作,但我看到一个额外的请求/%3Canonymous%3E返回 404。这导致 Redux 中出现以下错误:
未处理的拒绝(TypeError):无法读取未定义的属性“数据”
我在其他组件中对其他路由的请求中没有看到 404,例如来自用户组件的 /api/users。我已更改获取请求和路由以匹配用户的请求和路由,但问题仍然存在。我已经在邮递员中尝试过该请求,它响应了预期的结果。仅当向浏览器中的订单资源(从应用程序)发出 get 请求时,才会发生对 /%3Canonymous%3E 的附加请求。
获取请求:
export const getOrders = () => dispatch => {
axios
.get("api/orders/")
.then(res =>
dispatch({
type: GET_ORDERS,
payload: res.data
})
)
.catch(err =>
dispatch({
type: GET_ERRORS,
payload: err.response.data
})
);
};
Run Code Online (Sandbox Code Playgroud)
订购路线:
router.get(
"/",
(req, res) => {
Order.find()
.then(orders => res.json(orders))
.catch(err => {
res.json(err);
});
}
);
Run Code Online (Sandbox Code Playgroud)
getOrder 减速器:
case GET_ORDERS:
return {
...state,
allOrders:
action.payload
};
Run Code Online (Sandbox Code Playgroud)
整个阶数缩减器:
import {
GET_ORDERS,
ADD_ORDER,
EDIT_ORDER, …Run Code Online (Sandbox Code Playgroud) 我有一个公共“项目符号”数组,我正在将私有项目符号对象推入其中。它具有 x 和 y 属性,我想更改它的 y 属性,以便每次按空格键时,它都会创建一个项目符号对象,将其推入项目符号数组,然后调用一个循环遍历数组并更新每个项目符号 y 的函数财产。
但是,每次按空格键时都会出现错误:
未捕获的类型错误:无法读取未定义的属性“y”
这稍微超出了我的理解,我不知道如何编写这个,以便项目符号数组中的项目符号对象不是“未定义”。
如果有人有任何建议,我将不胜感激。
//called every frame
function playGame()
{
movePlayer();
playerShoot();
moveBullet();
}
//PLAYER SHOOT FUNCTION
//If the space key is down, player.shoot is true and the bullet object is created.
function playerShoot()
{
if(player.shoot)
{
var bullet = Object.create(spriteObject);
bullet.width = 16;
bullet.height = 16;
bullet.x = (player.width - bullet.width) / 2;
bullet.y = (player.height - bullet.height) / 2;
bullets.push(bullet);
player.shoot = false;
}
}
//MOVING THE BULLET
function …Run Code Online (Sandbox Code Playgroud) 我无法在ajax.Getting Uncaught TypeError: Cannot read property 'customers' of undefined错误中使用jquery获取JSON数据.
<script type="text/javascript">
$("#savechanges").click(function(e) {
e.preventDefault();
jQuery.ajax({
url: "<?=base_url()?>customers/updatecustomerorderdetail",
data: $('#savecustomer input').serialize(),
type: "POST",
dataType: 'json',
beforeSend: function() {
//$("#update_"+id).html('');
$("#savechanges").html('<i class="fa fa-spinner fa-spin"></i>updating...');
},
success:function(data){
var customer_name = data[0].customers[0].customer_name;
alert(customer_name);
console.log(data);
},
error:function (error){
console.log(error);
}
});
});
Run Code Online (Sandbox Code Playgroud)
来自上面代码的JSON响应
{
"customers":[
{
"customer_id":22,
"customer_name":"fggfd",
"customer_email":"fggd",
"customer_mobile":"dfgf",
"updated_user_id":"5",
"updated_datetime":"2018-07-30 21:00:57"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想customer_name从ajax的成功函数中的JSON数据中提醒.任何人都可以告诉我这里做错了什么?