一个例子
1、在"d:\web"目录下,建立一个子目录lib,在这个目录建立一个文本文件,文件名为"ajaxform.js",文件内容为:
//异步发送对象
function sendJsonObjectAsyn(){
var
obj=new Object();
obj.name = "hehui";
obj.age=39;
sendAjaxJSON(obj,"json.htm","afterSendJson");
//afterSendJson为发送完成后要执行的对象
}
//异步发送JSON字符串
function
sendJsonStringAsyn(){
var val= '{"name":"李云龙","age":"36"}';
sendAjaxJSON(val,"json.htm","afterSendJson");//afterSendJson为发送完成后要执行的对象
}
//显示服务器返回的数据
function
afterSendJson(result){
document.getElementById("p1").innerHTML=result;
}
2、HttpRequest事件代码:
Select
Case
e.Path
Case
"test.htm"
Dim
wb
As
New
weui
wb.AddForm("","form1","test.htm")
With
wb.AddButtonGroup("form1","btg1",True) '垂直排列
.Add("btn1", "发送jason对象","button").Attribute=""
.Add("btn2",
"发送jason字符串","button").Attribute=""
End
With
wb.AppendHTML("<div
id='p1' style='margin:0.5em'></div>") '插入一个div,用于显示服务器返回的数据
wb.AppendHTML("<script
src='./lib/ajaxform.js'></script>") '引入脚本文件
e.WriteString(wb.Build) '生成网页
Case
"json.htm"
Dim
sb
As
New
StringBuilder
Dim
jo
As
JObject = JObject.Parse(e.PlainText)
sb.AppendLine("服务器收到的数据有:<br/>")
sb.AppendLine("name:"
&
jo("name").ToString
&
"<br/>")
sb.AppendLine("age:"
&
jo("age").ToString)
e.WriteString(sb.ToString)
End
Select
按帮助这个例子测试的时候,浏览器的console显示“Uncaught ReferenceError: sendJsonObjectAsyn is not defined at HTMLButtonElement.onclick ((index):15)”
自己做的项目也是,引用ajax的时候都显示这个,这个如何解决呢?