从客户端到服务器端的Ajax Post记录错误

时间:2018-04-25 09:26:01

标签: javascript ajax asp-classic

我正在尝试创建一个ajax post函数,它可以在运行时记录错误并将它们静默发送到服务器端

这是我发布的用于从客户端页面发布数据的代码

var isDebugging = false;
var logJsErrors = true;
alert('passed variable decleration');
function ErrorSetting(msg, file_loc, line_no) {
    alert('entered the error setting method');
    var e_msg = msg;
    var e_file = file_loc;
    var e_line = line_no;
    var error_d = "Error in file: " + file_loc +
        "\nline number:" + line_no +
        "\nMessage:" + msg;
    if (logJsErrors) {
        theData = "file=" + file_loc + "&line=" + line_no + "&err=" + msg;
        alert('passed logging errors');
        ajaxCtrl(
            function () {
                return true;
            }, "http://localhost:57410/ServerPage.aspx", theData
        );
        alert('passed the ajax post');
    }

    if (isDebugging)
        alert("Error Found !!!\n--------------\n" + error_d);

    return true;
        }
    window.onload = ErrorSetting;

这是Ajax post function

的定义

var callInProgress = false;
var xmlHttp;
function ajaxCtrl(fnfragment,theUrl,theData){
	
	var bAsync = true;

	this.xmlHttp = XmlHttp.create();

	if(theUrl)
		var url = theUrl; 
	else{
		alert('Target URL is Empty');
		return false;
	}
	try {
		xmlHttp.open("POST", url,bAsync);
	   	callInProgress = true;
	}catch(e){
	   	callInProgress = false;
	   	return false;
	}
	if (bAsync) {
		xmlHttp.onreadystatechange= function(){
			//alert(xmlHttp.readyState);
			switch (xmlHttp.readyState) {
				case 4:
					callInProgress = false;
					if(fnfragment){
						fnfragment();

						// Clean up so IE doesn't leak memory
						//delete xmlHttp.onreadystatechange;
						//xmlHttp = null;

					}
					break;
			}
			/* if(xmlHttp.readyState == 4){
				callInProgress = false;
				if(fnfragment){
					fnfragment();

					// Clean up so IE doesn't leak memory
					//delete xmlHttp.onreadystatechange;
					//xmlHttp = null;

				}
			} */
		}
	}

	xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded;charset=UTF-8");

	if(theData)
		theKeyValPair = theData;
	else
		theKeyValPair = "";

	try {
		callInProgress = true;
		xmlHttp.send(theKeyValPair);
	}
	catch (e) {
		callInProgress = false;
		alert("Could not contact Server at this Time. Please Try again Later");
		return false;
	}

	if (!bAsync) {
	    done();
	}
}

这是我试图添加到服务器端以从客户端页面获取数据的VB脚本

IF (request.form("") && request.form("file")!="") THEN

        Set fcontent = Date+request.form("file")+"\t"+request.form("line")+"\t"+request.form("err")+"\r\n"
        MsgBox(fcontent);
        WriteToFilecustom(fcontent)
    END IF                
        function WriteToFilecustom(log)
 
        set filename = "Logs\errorlog.txt"
        Dim fso, fs,tfile,fo
        Set fso = CreateObject("Scripting.FileSystemObject")
    IF (fso.FileExists(filename)) then
        const ForAppending =8
        Set tfile = fso.OpenTextFile(filename, ForAppending ,true)
        tfile.WriteLine(log)
        else
       
         Set fo=fso.GetFolder(".\Logs")
         Set tfile=fo.CreateTextFile(name,false)      
         tfile.WriteLine(log)
    END IF
         tfile.Close
         Set fo = Nothing
         Set fso = Nothing   
            
         end function

我不明白我的错误在哪里因为我的post方法调用了URL但我无法发布数据

0 个答案:

没有答案