function changeNums(id,v,obj){ $.ajax({ type: 'POST', dataType: 'text', url: "car.php?act=change_num", data: {id: id, v: v}, success: function (res) { if (res.error == 1) { alert("错误"); } else { obj.val(v); changeAmount(res); //$("#count").text("¥" + res.total); } } }); }
时间: 2024-02-14 21:19:43 浏览: 6
这段代码是一个使用 jQuery 发送 AJAX 请求的函数。函数名为 changeNums,用来改变商品数量,参数包括商品 ID、数量和 jQuery 对象。函数内部使用 $.ajax 方法发送 POST 请求到指定的 URL("car.php?act=change_num"),并将商品 ID 和数量作为参数传递。当请求成功返回时,根据返回的结果更新页面中的商品数量和总价。如果出现错误,弹出错误提示框。
相关问题
修改并完善//修改按钮 $('#updat').on('click', function () { model.show() title.html('修改') $('[name="enable"]:first').prop('checked', true) get(tdHandle.find('a:first').data('id')) function get(id) { $.ajax({ url: 'http://yes.usermanager.com/dept/get/' + id, type: 'get', headers: { 'content-type': 'application/json' }, // data: JSON.stringify(obj), success: function (res) { console.log(res) if (res.code === 200) { alert('成功') } closeModel() init() } }) } $('#save-btn').click(function() { if (tdHandle.find('a:first').data('id')) { update(tdHandle.find('a:first').data('id')) } function update(id) { $.ajax({ url:'' }) } }) })
根据你的问题,我看到这段代码是用于修改部门信息的。我发现在点击修改按钮时,会调用一个名为 model 的函数,但是这个函数没有定义。因此,需要先定义一个 model 函数并在其中添加相应的代码。另外,在 update 函数中,url 参数为空,需要填入正确的接口地址。
以下是修改并完善后的代码:
```
// 修改按钮
$('#updat').on('click', function () {
model() // 调用 model 函数
title.html('修改')
$('[name="enable"]:first').prop('checked', true)
get(tdHandle.find('a:first').data('id'))
function model() {
// 添加代码
$('#myModal').modal('show')
$('#modal-title').text('修改部门信息')
$('#save-btn').text('保存')
}
function get(id) {
$.ajax({
url: 'http://yes.usermanager.com/dept/get/' + id,
type: 'get',
headers: {
'content-type': 'application/json'
},
success: function (res) {
console.log(res)
if (res.code === 200) {
alert('获取成功')
}
closeModel()
init()
}
})
}
$('#save-btn').click(function() {
if (tdHandle.find('a:first').data('id')) {
update(tdHandle.find('a:first').data('id'))
}
})
function update(id) {
$.ajax({
url: 'http://yes.usermanager.com/dept/update/' + id, // 修改接口地址
type: 'put',
headers: {
'content-type': 'application/json'
},
data: JSON.stringify(obj),
success: function (res) {
console.log(res)
if (res.code === 200) {
alert('修改成功')
}
closeModel()
init()
}
})
}
})
```
obj.find('name').text AttributeError: 'NoneType' object has no attribute 'text'
在这个错误信息中,'NoneType' object has no attribute 'text' 表示对象为None,即没有找到对应的标签值。具体地,obj.find('name')返回的是None。所提供的解决方案是,在使用find函数之后,添加一句判断语句,如果找不到对应的标签,就将其默认值设为0。例如,可以使用以下代码来解决这个问题:
```python
if obj.find('name'):
name = obj.find('name').text
else:
name = 0
```
这样,如果找不到name标签,变量name的值就会被设为0,避免了AttributeError的出现。请注意,这只是一种可能的解决方案,根据具体情况可能需要做出适当的修改。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Python学习笔记:‘’AttributeError: NoneType object has no attribute‘’](https://blog.csdn.net/lvsehaiyang1993/article/details/80910104)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [关于 AttributeError: ‘NoneType‘ object has no attribute ‘text‘ 的三种解决方法](https://blog.csdn.net/qq_55535816/article/details/121456901)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]