javascript - jsonp : Uncaught SyntaxError: Unexpected token < -
i need load aspx page returns string of text using jsonp since cross domain call. target page loaded inside div tag , displayed modal window on source page.
i using test form pass 3 parameters target page expects, submit button, simple.
when submit page, error message: uncaught syntaxerror: unexpected token <
when click on error see error points line:
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">
this first time working json/ jsonp, , not sure how fix error. possible figure out?
my invoking page:
<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> $(function () { $("#dialog").dialog({ autoopen: false, modal: true, title: "details", buttons: { close: function () { $(this).dialog('close'); } } }); $("#btnsubmit").click(function () { $.ajax({ type: "get", datatype: "jsonp", crossdomain: true, url: "http://localhost:81/order-error.aspx", contenttype: "application/json; charset=utf-8", data: { 'order': $("#order").val(), 'site': $("#site").val(), 'env': $("#env").val() }, success: function (r) { $("#dialog").html(r.d); $("#dialog").dialog("open"); } }); }); }); </script> </head> <body> <table> <tr> <td>name:</td> <td><input type="text" id="order" value="" /></td> <td><input type="text" id="site" value="" /></td> <td><input type="text" id="env" value="" /></td> </tr> <tr> <td><input type="button" id="btnsubmit" value="submit" /></td> </tr> </table> <div id="dialog" style="display: none"> </div> </body> </html>
my target/ response page (order-error.aspx):
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title></title> <style type="text/css"> body { margin: 0; padding: 0; font-size: 11px; font-family: 'segoe ui', tahoma, geneva, verdana, sans-serif; } #content { width: 100%; display: inline-block } .label { position:relative; float:left; top:0; margin-right:5px; } </style> </head> <body> <div id="content"> <div class="order"> <div class="label">web order#: </div> <div id="orderno" runat="server" class="value"></div> </div> <div class="error"> <div class="label">message: </div> <div class="value"> <asp:label id="lblordererror" runat="server" visible="false"></asp:label></div> </div> </div> </body> </html>
and code behind:
partial class order_error inherits system.web.ui.page protected sub page_load(sender object, e eventargs) handles me.load dim sitekey string = string.empty dim orderid string = string.empty sitekey = request.querystring("site").trim orderid = request.querystring("order").trim me.lblordererror.text = functions.getaxerrormessage(sitekey, orderid) me.orderno.innertext = orderid.trim lblordererror.visible = true end sub end class
the output html of order-error.aspx:
<html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="content-type" content="text/html; charset=utf-8" /> </head> <body> <div id="content"> <div class="order"> <div class="label">web order#: </div> <div id="orderno" class="value">a1g759</div> </div> <div class="error"> <div class="label">message: </div> <div class="value"> <span id="lblordererror"><fault xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/fault"> <code /> <reason> <text xml:lang="en-us">user not authorized endpoint.</text> </reason> </fault></span></div> </div> </div> <!-- visual studio browser link --> <script type="application/json" id="__browserlink_initializationdata"> {"appname":"chrome","requestid":"757708942b1d4af892b199f3590d85f5"} </script> <script type="text/javascript" src="http://localhost:63737/17a3dfffdc8f48ad9496d260bd296120/browserlink" async="async"></script> <!-- end browser link --> </body> </html>
the error caused ajax call return html instead of json.
in success
handler have $("#dialog").html(r.d);
. here try parse output of call (r
) object (r.d
forces this), fails obvious reasons.
you should return json ajax method, possibly using http handler or webapi.
Comments
Post a Comment