Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

post a link from jquery to call a ASHX asp.net

Tags:

jquery

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 (undefined)
POST http://localhost:1111/abc.aspx undefined (undefined)

How can I solve this problem?

thanks in dvance.

like image 949
olidev Avatar asked Nov 27 '25 01:11

olidev


1 Answers

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/

like image 177
jk. Avatar answered Nov 28 '25 15:11

jk.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!