post a link from jquery to call a ASHX asp.net
I have this function:
function exportdata(ID) {
$.ajax({
type: "POST",
url: "export.ashx?ID=" + ID,
data: "{}",
/*contentType: "application/json; charset=utf-8",*/
dataType: "json"
});
}
It works fine but when I open the Developer Tools of Chrome in the Console tab, I see some errors:
POST http://localhost:1111/export.ashx?ID=1 undefined开发者_StackOverflow社区 (undefined)
POST http://localhost:1111/abc.aspx undefined (undefined)
How can I solve this problem?
thanks in dvance.
It may be caused by this:
data: "{}",
When you use braces to send data to $.ajax
, you do not need quotes around them:
data: {},
The quotes come in when you want to send data in this fashion:
data: "name=John&location=Boston",
Also, data
is not required. If you are not sending any data, simply omit it.
Documentation for jquery ajax: http://api.jquery.com/jQuery.ajax/
The parameter coming in is ID and you're using tripID in the code. Could that be it?
Try this
function exportdata(tripID) {
$.ajax({
type: "POST",
url: "export.ashx?ID=" + tripID,
data: "{}",
/*contentType: "application/json; charset=utf-8",*/
dataType: "json"
});
}
If you aren't posting any data and just want to pass a query-string variable you have to use GET:
$.ajax({
type: "GET",
url: "export.ashx?ID=" + ID
});
精彩评论