Posting data to colorbox iframe?

Here is the code I'm working with. From the other examples I've seen, this should work, but it is not. And already made sure that I use the latest colorbox.

function updateFolderCate(ID,Type){ $.colorbox({ iframe:true, scrolling: false, innerWidth:'100', innerHeight:'100', href:"page.php", data:{LinkID:ID,itemType:Type}, onClosed:function(){ //Do something on close. } }); } 
+4
source share
4 answers

You set the iframe to true. What it does is open a colorbox, create an iframe, and set the src iframe attribute to the location specified by href. Therefore, logically this cannot do POST requests. This may accomplish what you want, but I'm not sure.

 function updateFolderCate(ID,Type){ $.colorbox({ open: true, scrolling: false, innerWidth:'100', innerHeight:'100', href:"page.php", data:{LinkID:ID,itemType:Type}, onClosed:function(){ //Do something on close. } }); } 

This will not behave exactly as the iframe method does. You may need to rework your endpoint. If your endpoint should not receive POST requests, then head back with earlonrails.

EDIT: I came to this after diving the source code: Source

The corresponding lines are line 800 and line 856. iframe and href did not seem to be compatible, so I checked the element that was loaded into Firebug and noticed that it was an iframe with the src attribute set to the href variable.

+11
source

He says: ".load (url [, data] [, complete (responseText, textStatus, XMLHttpRequest)]) urlA string containing the URL to which the request is sent. DataA map or a string that is sent to the server with the request."

And you have a href object, but I don't think they are used together in this case. To use .load or data in this case, I think you will need to provide a url. I think any of these methods may work.

  function updateFolderCate(ID,Type){ $.colorbox({ iframe:true, scrolling: false, innerWidth:'100', innerHeight:'100', href:"page.php?LinkID=" + ID + "&itemType=" + Type, // or data : { "page.php", { LinkID:ID,itemType:Type } } onClosed:function(){ //Do something on close. } }); } 

http://www.codingforums.com/showthread.php?t=158713

http://api.jquery.com/load/

+3
source

You can open a blank page in an iframe that receives data from the top page and places it as such:

 var postData = window.top.getDataToPost() $.post(postUrl,postData) 

On the page that opens colorbox, create a function to provide the value

 function getDataToPost() { return { param1 = value1 } } 
+1
source

In your code example, data is an object. In this case, it is created by the object literal syntax.

What exactly is going on?

  • In which browser (including version number) have you tried it?

  • What version of jQuery are you using?

  • Are you getting any errors in the console?

  • Have you looked at the request on the Firebug network tab (or other developer tools / Fiddler / etc.) to see exactly what is in the request (for example, the request method) and the server response?

  • Have you tried the query directly using jQuery.load() to find out what will happen?

0
source

Source: https://habr.com/ru/post/1401835/


All Articles