jQuery的AJAX的responseText'不确定' [英] jQuery ajax responseText 'undefined'
问题描述
我有一些jQuery哪些职位两个变量的PHP脚本。 PHP的非常简单,只是返回基于什么它给了一个字符串,即更新成功,我想在页面上的一些方法来使用。
我第一次点击,我得到一个警告说未定义,任何进一步的点击,一切工作正常。 pretty的肯定,我已经不远了,但我不能工作了这个问题!
我用萤火虫和数据发布和正确的响应收到的所有努力。
$(文件)。就绪(函数(){
$('#updatehol)。点击(函数(){
添加= $('#添加')ATTR('值')。
扣除= $('#扣减)ATTR('值')。
datastring ='添加='+添加+'和;扣除='+扣除;
$阿贾克斯({
键入:POST,
数据:datastring,
网址:doadjust.php
完成:功能(数据){
警报(data.responseText);
}
});
});
});
排序它。需要异步:在阿贾克斯函数假
选项
$。阿贾克斯({
键入:POST,
数据:datastring,
网址:doadjust.php
数据类型:HTML,
异步:假的,
成功:功能(数据){
警报(数据);
}
});
I've got some jQuery which posts two variables to a php script. The PHP is very simple and simply returns a string based on what it's given, i.e. 'update successful' which I'd like to use in some way on the page.
The first time I click I get an alert saying 'undefined', any further clicks and everything works fine. Pretty sure I'm not far off but I can't work out this problem!
I've used firebug and the data is posted and the correct response is received on all attempts.
$(document).ready(function(){
$('#updatehol').click(function() {
additions = $('#additions').attr('value');
deductions = $('#deductions').attr('value');
datastring = 'additions='+ additions +'&deductions='+ deductions;
$.ajax({
type: "POST",
data: datastring,
url: "doadjust.php",
complete: function(data) {
alert(data.responseText);
}
});
});
});
Sorted it. Needed async: false
option in the Ajax function.
$.ajax({
type: "POST",
data: datastring,
url: "doadjust.php",
dataType: "html",
async: false,
success: function(data) {
alert(data);
}
});
这篇关于jQuery的AJAX的responseText'不确定'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!