0

I have to decode response message from external web site (so, it's not possible to change the way they return messages), but it does not work in Fancybox modular pop-up where this page is loaded.

I'm using in such way (it works fine when page loads as "simple page", but not - when open this page using Fancybox jQyery plugin):

var response = JSON.parse(decodeURIComponent(h.url.param.get("response")));

the response looks like this:

response={%22Message%22%3a%22response+message+%3Ca+href%3d%27http%3a%2f%2fwww.linktosomeurl.com%27+target%3d%27_blank%27%3Eclick+here.%3C%2fa%3E%22}

it should return "message click here" (and click here is as link to www.linktosomeurl.com)!

as I said - it works fine when just open page. But the problem is that it does not get response message if open the page in fancybox (somehow fancybox jQuery breaks this response message because of the a href url inside it).

is there a way how I can get this response message with url also using Fancybox?

Any hint about the problem would be appreciated...really stuck with this ;-(

JFK
  • 40,963
  • 31
  • 133
  • 306
Mole_LR
  • 69
  • 1
  • 10
  • Is `response` returned as `object` or `string` ? – guest271314 Sep 29 '14 at 02:28
  • @guest271314 : I guess as object sin the OP is using `JSON.parse` – JFK Sep 29 '14 at 02:31
  • as object...it has not just message, but other variables also there..."message" is just one of them! – Mole_LR Sep 29 '14 at 02:31
  • so far the simpliest way I could figure out - in my side replace text "sometext" with this url and ask external site stuff to change in their side this url with "sometext"... – Mole_LR Sep 29 '14 at 02:32
  • @Mole_LR : your response doesn't look well formed, how does it work when it loads as "simple page"? could you create a jsfiddle with that object variable? (without fancybox) – JFK Sep 29 '14 at 02:33
  • but it's like bypath, not the finding the reason and solution of the problem... – Mole_LR Sep 29 '14 at 02:33
  • it's formated by external url stuff, and it's correct, maybe I "mess some string" there, in "clean" display it is: response={"Message":"response message click here."} And in "simple page" it works creating div element with message text and display for X seconds (using externul url js source) or just using alert(response.message) and it shows whole response message including this url! – Mole_LR Sep 29 '14 at 02:35
  • @Mole_LR @JFK If try `response={%22Message%22%3a%22response+message+%3Ca+href%3d%27http%3a%2f%2fwww.linktosomeurl.com%27+target%3d%27_blank%27%3Eclick+here.%3C%2fa%3E%22}` at `console` get `SyntaxError: Unexpected token %` ? Certain `response` not `string` ? – guest271314 Sep 29 '14 at 02:45
  • "whole" (full) response looks like this: ?response={%22Code%22%3a-999%2c%22Success%22%3afalse%2c%%22Message%22%3a%22response+message+%3Ca+href%3d%27http%3a%2f%2fwww.linktosomeurl.com%27+target%3d%27_blank%27%3Eclick+here.%3C%2fa%3E%22%2c%22Data%22%3anull}. What I'm doing - this response is returned to "my url", then I read this full response and add it to the page I'm opening in fancybox (otherwise fancybox can not get this url, just adding again respone url ?response= to the page I'm opening)! ;-) – Mole_LR Sep 29 '14 at 02:48
  • Appear to be `string` , with `?` at first character ? Is call `jsonp` ? If possible , can try `console.log(typeof response)` , post what is returned ? See updated post , including leading `?` . Thanks – guest271314 Sep 29 '14 at 02:56
  • console.trace() app.js:9645migrateWarn app.js:9645Object.defineProperty.set app.js:9664(anonymous function) app.js:22385(anonymous function) – Mole_LR Sep 29 '14 at 03:00

2 Answers2

0

Try

var res = "?response={%22Message%22%3a%22response+message+%3Ca+href%3d%27http%3a%2f%2fwww.linktosomeurl.com%27+target%3d%27_blank%27%3Eclick+here.%3C%2fa%3E%22}";

var response = $.parseHTML(decodeURIComponent(res.split(/\=\{|\}/)[1]).replace(/response|message|\+/gi," "))[1];

$("body").append(response)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
guest271314
  • 1
  • 15
  • 104
  • 177
0

so far not find the solution, but used workaround, more flexible than answered before - asked external site owners to change response message use link as plain text, and at my side change plain text link to a href link as described here: How to replace plain URLs with links? so far works fine! Not real solution, but quite good workaround to save time...

thanks for hints, suggestions to all! ;-)

Community
  • 1
  • 1
Mole_LR
  • 69
  • 1
  • 10