Advertisement

05.16.2008 at 07:56AM PDT, ID: 23408505
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.6

Language / URL Encoding Nightmare (javascript, prototype/ajax, asp, ado, sql server)

Asked by TheFoot in JavaScript, Active Server Pages (ASP)

Tags:

Hi.

I have an ajax-driven (prototype) form that posts to an asp server script to save to the database.  The text language is German, and the characters are getting corrupted by the time it gets to the database.  I will post the code after..

If I call the ajax script directly with either of the following URLs:

/ajax/menu-saveitem.asp?vCMS_MENU_ID=5&vCMS_MENU_ITEM_ID=146&vPARENT_MENU_ITEM_ID=&vDISPLAY_NAME=Kapitalm%E4%EBrkte&vCMS_PAGE_ID=1
/ajax/menu-saveitem.asp?vCMS_MENU_ID=5&vCMS_MENU_ITEM_ID=146&vPARENT_MENU_ITEM_ID=&vDISPLAY_NAME=Kapitalmäërkte&vCMS_PAGE_ID=1

.. then the save works properly, and the actual value held in the SQL Server 2000 table for DISPLAY_NAME is "Kapitalmäërkte".

However when I use the ajax form to post it, it saves to the database as "Kapitalmäërkte".  I use Firebug to show what data is being posted, and the URL escaped value "Kapitalm%C3%A4%C3%ABrkte" is sent to the server.  The URL escaped value here is different to the URL escaped value that I used in the above querystring URL.

All pages are utf-8 encoded, and the documentation for prototype says that ajax requests are all utf-8 encoded.  I have tried various methods of URL encoding on the client, and URL decoding at the server.  Nothing seems to work, at least I cant make sense of any of it.

I think the problem lies in the different values that are posted to the server.  I use form POSTs, but to test the ajax script I used the GET/querystring method.

I really need some help on this as I cannot make head nor tail of what is going on!!  How do I make the ajax script post the data in the same encoding as the first line of the direct ajax test URLs?  I think that would fix the problem.

Thanks, TheFootStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
======================
AJAX CLIENT POST SCRIPT
======================// Build parameters
		    sParams = 'vCMS_MENU_ID=' + $('vCMS_MENU_ID').value;
		    sParams += '&vCMS_MENU_ITEM_ID=' + $('vCMS_MENU_ITEM_ID').value;
		    sParams += '&vPARENT_MENU_ITEM_ID=' + $('vPARENT_MENU_ITEM_ID').value;
		    sParams += '&vDISPLAY_NAME=' + $('vDISPLAY_NAME').value;
		    sParams += '&vCMS_PAGE_ID=' + $('vCMS_PAGE_ID').value;
		    sParams += '&vURL=' + $('vURL').value;
		    sParams += '&vORDER_NO=' + $('vORDER_NO').value;
 
		    // Save via ajax
		    new Ajax.Request('/ajax/menu-saveitem.asp', {
          method: 'post',
          parameters: sParams,
          onComplete: function(transport){
       
            var oReturn = eval("(" + transport.responseText + ")");
        
            if (oReturn.sErrorMsg.length > 0){
              // Failed
              $('divAjaxStatus').update('Error: ' + oReturn.sErrorMsg).show();
            }else{
              // Success
              gfPropertiesEditYN = false;
              $('divNewRecordStatus').hide();
              nCurrentMenuItemID = oReturn.nMenuItemID;
              $('vCMS_MENU_ITEM_ID').value = nCurrentMenuItemID;
              $('vMenuItemID').value = nCurrentMenuItemID;
              $('vModifiedTS').value = new Date();
              fnRefreshMenu();
              $('divAjaxStatus').hide();
            }
          },
          onFailure: function(transport){
            divStatus.update('An error occurred while contacting the server.  Please refresh the page.').show();
          }
        });
 
======================
AJAX SERVER SCRIPT
======================
'// Check session
  sErrorMsg = fnCheckSession(true)
  
  if len(sErrorMsg) = 0 then
    nMenuID = numConvertLong(request("vCMS_MENU_ID"))
    nMenuItemID = numConvertLong(request("vCMS_MENU_ITEM_ID"))
    nParentMenuItemID = numConvertLong(request("vPARENT_MENU_ITEM_ID"))
    sDisplayName = request("vDISPLAY_NAME")
    nPageID = numConvertLong(request("vCMS_PAGE_ID"))
    sURL = nz(request("vURL"), "")
    nOrderNo = numConvertLong(request("vORDER_NO"))
    
    set oConn = ConnectDB(false, sErrorMsg)
    set rstTemp = server.CreateObject("ADODB.Recordset")
    with rstTemp
      .CursorLocation = adUseClient
      .CursorType = adOpenKeyset
      .LockType = adLockBatchOptimistic
      .ActiveConnection = oConn
      .Open "select * from dt_CMS_MENU_ITEM where CMS_MENU_ITEM_ID = " & nMenuItemID
      .Fields("CMS_MENU_ID") = nMenuID
      .Fields("PARENT_MENU_ITEM_ID") = iif(nParentMenuItemID < 1, null, nParentMenuItemID)
      .Fields("DISPLAY_NAME") = sDisplayName
      .Fields("CMS_PAGE_ID") = nPageID
      .Fields("URL") = sURL
      .Fields("ORDER_NO") = nOrderNo
 
      .updatebatch
      .Close
    end with
    set rstTemp = nothing
    if err <> 0 then sErrorMsg = err.Description
  
    '// Create JSON return object
    sBuffer = _
      "{" & vbcrlf & _
      "  'nMenuItemID':  '" & nMenuItemID & "'," & vbcrlf & _
      "  'sErrorMsg': '" & sErrorMsg & "'," & vbcrlf & _
      "}" & vbcrlf
    
  end if
 
  response.Write sBuffer
  response.end
[+][-]05.16.2008 at 08:10AM PDT, ID: 21583412

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.16.2008 at 09:21AM PDT, ID: 21584123

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.16.2008 at 11:53AM PDT, ID: 21585428

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: JavaScript, Active Server Pages (ASP)
Tags: url encoding javascript asp prototype
Sign Up Now!
Solution Provided By: TheFoot
Participating Experts: 0
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_EXPERT_20070906