I think you want to set the response of the call to the URL 'compz.php?prodid=' + x + '&qbuys=' + y
as value of the textbox right?
(我想你想设置调用URL的反应'compz.php?prodid=' + x + '&qbuys=' + y
作为文本框的值对吗?)
If so, you have to do something like:(如果是这样,你必须做以下事情:)
$.get('compz.php?prodid=' + x + '&qbuys=' + y, function(data) {
$('#subtotal').val(data);
});
Reference: get()
(参考: get()
)
You have two errors in your code:
(您的代码中有两个错误:)
load()
puts the HTML returned from the Ajax into the specified element:
(load()
将从Ajax返回的HTML放入指定的元素:)
Load data from the server and place the returned HTML into the matched element.
(从服务器加载数据并将返回的HTML放入匹配的元素中。)
You cannot set the value of a textbox with that method.
(您无法使用该方法设置文本框的值。)
$(selector).load()
returns the a jQuery object .
($(selector).load()
返回一个jQuery 对象 。)
By default an object is converted to [object Object]
when treated as string.(默认情况下,对象在被视为字符串时会转换为[object Object]
。)
Further clarification :
(进一步澄清 :)
Assuming your URL returns 5
.
(假设您的网址返回5
。)
If your HTML looks like:
(如果你的HTML看起来像:)
<div id="foo"></div>
then the result of
(然后结果)
$('#foo').load('/your/url');
will be
(将会)
<div id="foo">5</div>
But in your code, you have an input element.
(但是在你的代码中,你有一个输入元素。)
Theoretically (it is not valid HTML and does not work as you noticed), an equivalent call would result in(从理论上讲 (它不是有效的HTML,并且不像你注意到的那样工作),会导致等效的调用)
<input id="foo">5</input>
But you actually need
(但你真的需要)
<input id="foo" value="5" />
Therefore, you cannot use load()
.
(因此,您不能使用load()
。)
You have to use another method, get the response and set it as value yourself.(您必须使用其他方法,获取响应并自行将其设置为值。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…