Reputation: 1953
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.net 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
Upvotes: 1
Views: 2006
Reputation: 221997
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 */
}
})
Upvotes: 4
Reputation: 32107
jQuery.ajax({
url:'AjaxActions/OrderNotesUpdate.aspx',
data:{
OrderID:OrderID,
Notes:$('#txtNotes').val()
},
async:false,
type:'get',
success:function(data)
{
//do something here
}
})
Upvotes: 6