×

jquery ajax 简单范例(界面+后台)

作者:Terry2017.02.20来源:Web前端之家浏览:4644评论:0
关键词:JQueryJS
界面:
复制代码 代码如下:

<script>
$(document).ready(function () {
$("#b01").click(function () {
htmlobj = $.ajax({ url: "/Content/upFile/测试.txt", async: false });
$("#div01").html(htmlobj.responseText);
});
});

$(document).ready(function () {
$("#test").load("/Content/upFile/测试2.txt #p1", function (responseTxt, statusTxt, xhr) {
if (statusTxt == "success")
alert("外部内容加载成功!" + xhr);
if (statusTxt == "error")
alert("Error: " + xhr.status + ": " + xhr.statusText);
});
});

$(document).ready(function () {
$("#getbutton").click(function () {
$.get("/DownSet/index", function (data, status) {
alert("数据:" + data + "\n状态:" + status);
});
});
});

$(document).ready(function () {
$("#postbutton").click(function () {
$.get("/CustomerInformation/getS", { par: "ww" }, function (data, status) {
alert("数据:" + data + "\n状态:" + status);
$("#postText").html(data);
});
});
});

</script>
<div id="div04">
<h2 id="postText">post方法加载文本后 会在这里显示</h2>
<input type="button" value="post方法获取" id="postbutton" />
</div>

<div id="div03">
<h2 id="getText">get方法加载文本后 会在这里显示</h2>
<input type="button" value="get方法获取" id="getbutton" />
</div>

<div id="div02">
<h2>jquery load方法加载的显示在这里</h2>
<h2 id="test">加载文本后 会在这里显示</h2>
</div>

<div id="div01">
<h2>加载文本后 会在这里显示</h2>
</div>
<p>
<input type="button" value="加载文本" id="b01"/>
</p>

后台:
复制代码 代码如下:

public string getS(string par)
{
string content = "";
if (par.Equals("ww"))
{
content = "cheng gong le";
}
else
{
content = "shi bai le";
}
return content;
}

您的支持是我们创作的动力!
温馨提示:本文作者系Terry ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://jiangweishan.com/article/svg1487520000926.html

网友评论文明上网理性发言已有0人参与

发表评论: