I'm somewhat new to Ajax/Jquery, so I apologize if this is an easy question, but I just couldn't figure it out.
I am using CakePHP and JQuery.
I want to save a link, label, and description into a table by pulling out the "innerHTML" from an HTML page. I can't seem to put the data in the expected format - that is the format that the controller expects.
I am pulling the data from html, the html is like this:
<div class="listing">
<ul>
<li class="link">www.yahoo.com</li>
<li class="label">Yahoo</li>
<li class="description">This is Yahoo's home page</li>
</ul>
</div>
...
I can parse the HTML and get my "link", "label", and "description".
But, when I post the data to the controller, I can't figure out how to get the data in the expected format.
After pulling the data into variables with JavaScript (JQuery), I post it using the following JQuery function:
$.post("/links/save", {link: link, label: label, notes: description});
When the data posts to the controller, the format of the data is:
(
[form] => Array
(
[link] => www.yahoo.com
[label] => Yahoo
[description] => This is Yahoo's home page
)
)
The format that the controller expects the data is:
(
[data] => Array
(
[Link] => Array
(
[link] => www.yahoo.com
[label] => Yahoo
[description] => This is Yahoo's home page
)
)
)
I know I can take the data as it is and put it in the proper format in the controller, but it seems like that is unnecessary.
Can someone please tell me how to manipulate the data in the JQuery so that it posts as the controller expects it?