最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Losing unicode Char when sending via query string in an AJAX call - Stack Overflow

programmeradmin5浏览0评论

I'm trying to send some data in an Ajax call to update a record in the server

 var OrderNotes = $.ajax({
                 url:'AjaxActions/OrderNotesUpdate.aspx?OrderID=' + OrderID + '&Notes=' + $('#txtNotes').val(),
                 async:false                 
               }).responseText;

"Notes" are in unicode.

When i'm checking the querystring on the receiving page i'm getting not getting the same code (not the text i'v enterd).

Any one knows any thing about it? is it becouse the data is from an asp textbox? what can i do about it?

p.s before sending i checked and every things is as it should, just in the querystring every thing going wrong... 10x

I'm trying to send some data in an Ajax call to update a record in the server

 var OrderNotes = $.ajax({
                 url:'AjaxActions/OrderNotesUpdate.aspx?OrderID=' + OrderID + '&Notes=' + $('#txtNotes').val(),
                 async:false                 
               }).responseText;

"Notes" are in unicode.

When i'm checking the querystring on the receiving page i'm getting not getting the same code (not the text i'v enterd).

Any one knows any thing about it? is it becouse the data is from an asp textbox? what can i do about it?

p.s before sending i checked and every things is as it should, just in the querystring every thing going wrong... 10x

Share Improve this question edited Sep 25, 2010 at 8:53 Erez asked Sep 25, 2010 at 8:46 ErezErez 1,9535 gold badges29 silver badges59 bronze badges 1
  • Have a good reason for using async:false, it locks the client browser during the request. The most mon reason for using synchronous AJAX is the lack of understanding in how to implement a callback. – Matt Commented Sep 25, 2010 at 10:15
Add a ment  | 

2 Answers 2

Reset to default 6
jQuery.ajax({
            url:'AjaxActions/OrderNotesUpdate.aspx',
            data:{
                 OrderID:OrderID,
                 Notes:$('#txtNotes').val()
                 },
           async:false,
           type:'get',
           success:function(data)
                   {
                    //do something here
                    }
})

First of all the answer of Praveen Prasad I find correct. I want only to add a little description which will be answeron the question "Why ... ?" and not "How ... ?".

If parameter which you send to the server per HTTP GET has some special characters then there can not be used in URL without encoding, so you have to use at least

url:'AjaxActions/OrderNotesUpdate.aspx?OrderID=' +
    encodeURIComponent(OrderID) + '&Notes=' + encodeURIComponent($('#txtNotes').val())

Next step: you can use jQuery.param() to encode URL parameters with respect of encodeURIComponent and place '&' character between paramters:

$.ajax({
    url:'AjaxActions/OrderNotesUpdate.aspx?' +
        $.param({OrderID: OrderID, Notes: $('#txtNotes').val()}),
    async:false})

or

$.ajax({
    url:'AjaxActions/OrderNotesUpdate.aspx' +
    data: { OrderID: OrderID, Notes: $('#txtNotes').val()},
    async:false})

which place '?' between url and data encoded by $.param if url don't already contain '?' otherwise it use '&' instead.

Next: you should try to use asynchrone version of $.ajax whenever it is possible. One needs see more parts of your code to help you. In general it should be

$.ajax({
    url:'AjaxActions/OrderNotesUpdate.aspx' +
    data: { OrderID: OrderID, Notes: $('#txtNotes').val()},
    success:function(response) {
        /* here use can use response.responseText. For examlpe you can
           code which call the syncrone $.ajax before and used
           the return value here */
    }
})
发布评论

评论列表(0)

  1. 暂无评论