asp.net - Jquery AJAX to asmx web method get error as response -
ok, do:
client:
function ajaxcall(url, method, data, onsuccessfunction, onerrorfunction) { var ajaxdata = data; ajaxdata = json.stringify(ajaxdata); var ajaxurl = url + "/" + method; $.ajax({ type: "post", url: ajaxurl, data: ajaxdata, contenttype: "application/json; charset=utf-8", datatype: "json", success: function () { onsuccessfunction.apply(this, arguments); }, error: function () { $('.progressbar').hide(); onerrorfunction.apply(this, arguments); } }); } $(document).ready(function () { ajaxcall("http://localhost:34714/webservice1.asmx", "getchart", { filename: 'excel-demo.xlsx', sheet: 'chart_param' }, gettradingviewsuccess, gettradingviewerror) }); var gettradingviewsuccess = function (data) { } var gettradingviewerror = function (jqxhr, textstatus, errorthrown) { }
asmx:
using system; using system.collections.generic; using system.data; using system.data.oledb; using system.linq; using system.web; using system.web.script.services; using system.web.services; using webapplication2.classes; namespace webapplication3 { /// <summary> /// summary description webservice1 /// </summary> [webservice(namespace = "http://tempuri.org/")] [webservicebinding(conformsto = wsiprofiles.basicprofile1_1)] [system.componentmodel.toolboxitem(false)] // allow web service called script, using asp.net ajax, uncomment following line. // [system.web.script.services.scriptservice] public class webservice1 : system.web.services.webservice { [system.web.script.services.scriptmethod()] [webmethod] public string add() { return "sd"; } [webmethod(enablesession = true)] public chart getchart(string filename, string sheet) { chart c = new chart(); //do return c; } } }
web config:
<?xml version="1.0"?> <configuration> <system.web> <webservices> <protocols> <add name="httpget"/> <add name="httppost"/> </protocols> </webservices> <compilation debug="true" targetframework="4.5.1" /> <httpruntime targetframework="4.5.1" /> </system.web> </configuration>
and every time error message:
post http://localhost:34714/webservice1.asmx/getchart 500 (internal server error)send @ jquery-1.7.2.min.js:4f.extend.ajax @ jquery-1.7.2.min.js:4ajaxcall @ common.js:5(anonymous function) @ chart.html:15o @ jquery-1.7.2.min.js:2p.firewith @ jquery-1.7.2.min.js:2e.extend.ready @ jquery-1.7.2.min.js:2c.addeventlistener.b @ jquery-1.7.2.min.js:2 errorthrown "internal server error"
i put break point in asmx file - getchart webmethod, never reached it. doing wrong?
// allow web service called script, using asp.net ajax, uncomment following line.
uncomment line below that.
// [system.web.script.services.scriptservice]
becomes
[system.web.script.services.scriptservice]
Comments
Post a Comment