【发布时间】:2016-08-29 21:14:55
【问题描述】:
问题解决了。检查底部的工作代码。
首先,对不起我的英语。如果可能,请重写我的问题。
我无法通过调用 ajax 页面使用 jquery 更改输入值。
(jquery 版本http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js)
我的主页是 index.php,而 ajax 页面是 ajax.php。我用
调用了 ajax.php$.ajax(...
但是在使用 ajax 代码之后,index.php 上的输入值没有改变。
这里是 index.php 输入代码
<input name="guncel_fiyat" type="hidden" id="guncel_fiyat" value="old value">
这里是 index.php ajax 调用代码:
$.ajax(
{
type: "POST",
url: "../ajax.php",
data: post_edilecek_veri,
cache: false,
success: function(donen_veri)
{
some code here;
}
}
这里是 ajax.php 代码(我尝试了 3 种不同的方法,但没有任何改变)
$(".guncel_fiyat").val("new value");
或
$("#guncel_fiyat").val("new value");
或
$(".guncel_fiyat input").val("new value");
在调用 ajax 之后尝试在 index.php 上获取新值,但只获取“旧值”val。
var guncel_fiyat_degeri = $("#guncel_fiyat").val();
alert(guncel_fiyat);
这是工作代码
CALL_AJAX.HTML:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
function peyfunc()
{
"use strict";
var current_price = $("#current_price").val();
alert ("current_price="+current_price);
$.ajax(
{
url: "ajax_test.php",
cache: false,
success: function(html)
{
$("#display").html(html);
}
}
);
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post">
<input name="current_price" type="hidden" id="current_price" value="5">
<input type="button" name="button" id="button" value="Button" onclick="peyfunc()">
</form>
<div id="display"></div>
</body>
</html>
AJAX_TEST.PHP
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
test
<script type="text/javascript">
//alert("aaa");
$("#current_price").val("new value");
alert ($("#current_price").val());
</script>
【问题讨论】:
-
这个添加新值
$("#guncel_fiyat").val("new value");和这个警报url新值alert($("#guncel_fiyat").val("new value")); -
上传 ajax.php 和 ajax 调用的完整代码 我们可以帮助你,我们没有得到你实际尝试的内容。
-
现在我的代码可以工作了。
标签: javascript php ajax dom