07-08-2007, 17:13
|
|
|
חבר מתאריך: 21.05.03
הודעות: 576
|
|
בעית קידוד ב AJAX
אני מקווה שזה קשור לפה.
אני לא מצליח להעביר עברית כמו שצריך ב AJAX, זה הופך את העברית או לסימני שאלה או לסימנים מוזרים.
אני שולח טופס בקובץ HTML (קידוד של windows-1255) בעזרת ajax לסקריפט שנמצא בקובץ ASP.
בסקריפט שנמצא בקובץ ה-ASP אני מכניס את הנתונים למסד נתונים.
הבעיה היא שאני מקבל סימנים מוזרים בתוך המסד נתונים שהוא דרך אגב אקסס.
הבנתי שה ajax שולח את הנתונים ב unicode ולכן כשהוא מקבל את העברית שלי שהיא
ב windows-1255 הוא עושה סלט ירקות.
ובכלל המסד נתונים שלי לא נראה לי עובד ב unicode ולכן כשאני מכניס את הנתונים אליו הם גם הופכים לסימנים מוזרים(בקיצור סלט ירקות).
מה אפשר לעשות כדי לפתור את זה?
אני מוסיף את הקוד גם של הקובץ HTML וגם של הקובץ ASP.
קובץ ה HTML:
קוד:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=WINDOWS-1255">
<title>Ajax</title>
</head>
<body>
<script type="text/javascript">
function sendComment()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
var url="comment.asp";
var name = document.comment.name.value
var email = document.comment.email.value
var title = document.comment.title.value
var content = document.comment.content.value
var button = document.comment.button.value
url=url+"?name="+name+"&email="+email+"&title="+title+"&content="+content;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById("comment").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
</script>
<div id="comment"> </div>
<form dir=rtl name="comment" style="font-family:arial;color:white;font-size:10pt;">
שם: <input type="text" name="name" /><br/><br/>
אי מייל: <input type="text" name="email" /><br/><br/>
נושא: <input type="text" name="title" /><br/><br/>
תוכן ההודעה: <textarea name="content" rows=5 cols=30 wrap=virtual></textarea><br/><br/>
<input type="button" value="שלח" onclick="sendComment()" />
</form>
</body>
</html>
קובץ ה ASP:
קוד:
<%@ language="VBSCRIPT" codepage="1255"%>
<!--#include virtual = "/erezweb2/Adovbs.inc" -->
<%
name = request.querystring("name")
email = request.querystring("email")
title = request.querystring("title")
content = request.querystring("content")
set all_dataDB = Server.CreateObject("ADODB.Connection")
all_dataDB.Open "DSN=database;"
set comment = Server.CreateObject("ADODB.RecordSet")
comment.Open "comments", all_dataDB, adOpenStatic, adCmdTable
comment.AddNew
comment("Title") = title
comment("Content") = content
comment("Name") = name
comment("Email") = email
comment.Update
comment.Close
set comment = Nothing
all_dataDB.Close
set all_dataDB = Nothing
%>
name=<%=name%>
email=<%=email%>
בתודה מראש
ארז.
|