jQuery.get callback not firing from C# ASP.Net response -
I have a Bucommarket, which is clicked on, opens a Div popup on their current page (www .cnn.com). This div has a button, which requests jQuery.get for my application domain when clicking. It's all working fine, but I'm getting an error on the reaction. This is the function that requests
function postWishXML () {jQuery ("ServerSponse"). AjaxError (function (event, XMLHttpRequest, ajaxOptions) {// enter here}}; Var Wish = wishObject (); if (will == false) {jQuery ( '. Srhwarrspons'). Html (' Please enter a gift title '); jQuery (' GiftText. ') val (' ').} other {jQuery ('. ServerResponse '). Html (' '); Var WishXML = Create XMLTags (desire); JQuery.get (root +' / app / service / toolbar / Wishlist Popapkshaiks', { 'SAP' cookie, 'desire': WishXML}, Response, 'text');}
}
This is the server code
Public Zero Processing Request (HTTP Reference Reference) {if (Se curityContext.IsAuthenticated || SecurityContext.IsSemiAuthenticated) {if (! String.IsNullOrEmpty (context.Request [ "wish"])) {string res = "went the added desire"; Context.Response.ContentType = "text / plain "; context.Response.Write (race); context.Response.End ();
Post-text" Aitmprop = "text">I think you are right It seems that you are killing the cross-site scripting limit.
Remember, you are putting your javascript code in the code of the targeted website. Therefore, it seems that the code is running from their page. In other words, you are trying to make an AJAX request from within the page (e.g., www.cnn.com) and retrieve data from your site (other domains).
A solution I found article. This is an abstract:
function load script (scriptURL) {var scriptElem = document.createElement ('SCRIPT'); ScriptElem.setAttribute ('language', 'javascript'); ScriptElem.setAttribute ('src', scriptURL); Document.body.appendChild (scriptElem); } Load Script (root + '/apps/shop/toolbar/WishlistPopup.ashx');
Make JavaScript back to your server script that will be eval'ed.
Use a second, perhaps more preferred option. Basically, your server will respond with JSON data written in a named function. You tell the jQuery.ajax request that you expect a JasonP response and what the name of the returned function will be. It is working very much the above, but wrapped around it with a little more safety and syntax sugar.
This will be the PHP version, but it should be found throughout the point. Assume that all the data you need is in $ data and keep in mind that you can be able to handle the anonymous work in Jasonson structure successfully.
$ json = json_encode ($ data); Echo $ _GET ['jsonp_callback'] '('. $ Json. ');';
Javascript:
$ Ajax ({dataType: 'jsonp', jsonp: 'jsonp_callback', url: root + '/ apps / shop /toolbar/WishlistPopup.ashx', success: response,});
To steal the appropriate credit, I stole and modified this JSONP example from the answer of Andrew Moore
Comments
Post a Comment