0
contentType: "text/html; charset=utf-8",
url:"secret.aspx?plu="+$("#Text1").val()+"&gh="+$("#TextBox1").val()+"&sid="+$("#TextBox2").val(),
processData: false,
dataType: "html",
 success: function(data)

is it the above syntax correct to send the data recieved by the code below

string sid=Request.QueryString["sid"];
string id = Request.QueryString["plu"];
int ide =Convert.ToInt32(Request.QueryString["gh"]);
Response.write(sid);
Response.end();

or is there any other way to achieve the same

2
  • Did you run it and try? Commented Apr 26, 2014 at 17:29
  • yupp,not working@jonesy Commented Apr 26, 2014 at 17:32

2 Answers 2

1

The only problem with that request is that it will break if you have any special characters in your input values.

A solution to that would be to pass a data object:

type:"GET",
url:"secret.aspx",
data: {
    plu : $("#Text1").val(),
    gh : $("#TextBox1").val(),
    sid : $("#TextBox2").val()
},
dataType: "html",

This encodes special characters to avoid breaking the key/value format. Alternatively you could keep them in the url but wrap each in encodeURIComponent(), which would have the same effect.

Sign up to request clarification or add additional context in comments.

10 Comments

can this be retrieved using request.querystring @MrCode
Yes. jQuery converts it to a querystring behind the scenes. It's functionally the same as your original code but with the proper encoding included.
What happens if you navigate to the URL with your browser, passing some sample variables? to test the C# side.
OK so now open up the error console (F12), look at the Net/Network tab and watch the ajax request. See if there are any errors and see what the URL its requesting is.
500 Internal Server Error
|
0

You need to serialize your form data into the 'data' option of the ajax method. Also, specify the type of request as GET if you want to use the query string.

type: 'GET'
contentType: "text/html; charset=utf-8",
url:'secret.aspx',
processData: false,
dataType: "html",
data: $('#myForm').serialize(),

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.