0x800a139e-JavaScript运行时错误:语法错误,无法识别的表达式:#<;%=fieldGenieConnectionString.ClientID%>;
请参阅下面的代码:0x800a139e-JavaScript运行时错误:语法错误,无法识别的表达式:#<;%=fieldGenieConnectionString.ClientID%>;,javascript,ajax,Javascript,Ajax,请参阅下面的代码: function GroupUSNChange() { //$.ajax({ // type: "POST", // contentType: "application/json; charset=utf-8", // dataType: "html", // success: function OnSuccess(response) { var frm =
function GroupUSNChange() {
//$.ajax({
// type: "POST",
// contentType: "application/json; charset=utf-8",
// dataType: "html",
// success: function OnSuccess(response) {
var frm = document.forms[0];
var usn = document.getElementById("ctl00_ContentPlaceHolder1_hfUSN");
if (checkboxticked())
{
for (i = 0; i < frm.elements.length; i++) {
if (frm.elements[i].type == "checkbox" && frm.elements[i].name.substr(0, 38) == "ctl00$ContentPlaceHolder1$RematchGroup") {
if (frm.elements[i].checked == true) {
var id = frm.elements[i].name.split("|");
$.ajax({
type: "POST",
url: "frmPNList.aspx/ChangeGroupOfUSNs",
async: false,
contentType: "application/json; charset=utf-8",
data: '{strNewUSN: "' + usn.value + '", strURNs: "' + id[1] + '", strDatasetName: "' + id[2] + '", strCon: "' + $("#<%=fieldGenieConnectionString.ClientID%>")[0].value + '"}',
//data: '{strNewUSN: 9, strURNs: 1, strDatasetName: 2}',
dataType: "json",
success: OnSuccess(),
error: function (xhr, errorType, exception) {
var errorMessage = exception || xhr.statusText; //If exception null, then default to xhr.statusText
alert("there was an error changing the USN of the group: " + errorMessage);
},
failure: function () {
alert('there was an error changing the USN of the group.')
}
});
function OnSuccess() {
return function () {
}
}
//end of AJAX call
}
}
}
alert('Successfully changed the USN of the group')
//},
//error: function (xhr, errorType, exception) {
// var errorMessage = exception || xhr.statusText; //If exception null, then default to xhr.statusText
// alert("there was an error creating a screenshot (part one): " + errorMessage);
//},
//failure: function (reponse) {
// alert('there was a problem creating a screenshot.')
//}
//});
}
else
{
alert("You must tick at least one tickbox");
}
}
函数组usnchange(){
//$.ajax({
//类型:“POST”,
//contentType:“应用程序/json;字符集=utf-8”,
//数据类型:“html”,
//成功:函数OnSuccess(响应){
var frm=document.forms[0];
var usn=document.getElementById(“ctl00\u ContentPlaceHolder1\u hfUSN”);
如果(复选框勾选())
{
对于(i=0;i
当我将代码包含在.aspx文件中时,它就可以工作了。但是,当我创建一个.js文件并引用该.js文件时;我收到以下错误提示:您正在将ASP.NET(或其他服务器端代码)放入JS中
如果您的JS位于服务器正在以ASP.NET格式处理的文件中,则无需担心(只要数据正确转义或不包含特殊字符)
当您将其放入静态JS文件中时,服务器不再将其作为ASP.NET进行处理,并将代码发送到客户端……在客户端,服务器尝试将其作为JS执行,但失败了
要么:
- 将数据存储在HTML中并从DOM中读取
- 从ASP.NET生成JS文件(确保正确设置内容类型响应头)