我正在尝试从 PHP 获取数据并使用 jQuery 将其输入到 div
中。
第一次请求有效,但是,第二次请求后,它会清除 div 并将其设为空白。
这是我的 jQuery 代码
var post = document.getElementById('daddress_postcode').value;
var bottles = document.getElementById('bottletot').innerText;
$("#shipping").load("ship.php?postcode=" + post + "&bottles=" + bottles);
PHP 文件当前只有一个回显,返回一个字符串。
最佳答案
我解决了自己的问题。
问题出在变量上。 解决方案:
将请求更改为 POST
代码:
document.getElementById('shipping').innerHTML= '';
var post = document.getElementById('daddress_postcode').value;
var bottles = document.getElementById('bottletot').innerText;
$('#shipping').load("ship.php", {postcode:post,bottles:bottles});
这有效
看起来 URL 加入正在工作,但它不是从 post 返回一个字符串,而是返回一个 INT 的 URL,并且由于某种原因(有人可能能够详细说明)它没有更改它。
我保留了我的 post 方法,但也尝试显式地将 int 转换为字符串,有效
关于javascript - jQuery load() 方法在第二次运行后返回空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30966511/