dongxun6690 2013-04-19 22:23
浏览 44

JQuery Post Array to PHP

I know there are many questions about this, but none of which seem to allow me to understand. I have the following JS code:

function ClickToSave() {
var data1 = CKEDITOR.instances.textToBeSaved1.getData();
var data2 = CKEDITOR.instances.textToBeSaved2.getData();
var data3 = CKEDITOR.instances.textToBeSaved3.getData();
var data4 = CKEDITOR.instances.textToBeSaved4.getData();
var data5 = CKEDITOR.instances.textToBeSaved5.getData();
$.post('/admin/post_handler.php', {
page_content_1 : data1,
page_content_2 : data2,
page_content_3 : data3,
page_content_4 : data4,
page_content_5 : data5
})}

I'm trying to post this from CKEditor for a PHP page to pickup and know which data goes where. The JS is meant to save several inline DIV ID's simultaneously when the user clicks Save. I had this code working great when only using one DIV ID, but multiple is proving to be more challenging.

I'm having a little trouble replying to people as this site makes posts a little odd. The above code won't work. The following code does work:

function ClickToSave() {
var data1 = CKEDITOR.instances.textToBeSaved1.getData();
$.post('/admin/post_handler.php', {
page_content_1 : data1
})}

The HTML/PHP is as follows:

<?php echo '<div id="textToBeSaved1" contenteditable="true">'.$contentHere.'</div><button onclick="ClickToSave()">Save</button>'; ?>

The post_handler.php file only has this for testing reasons:

<?php file_put_contents('post_errors.php', $_POST['page_content_1']); ?>
  • 写回答

2条回答 默认 最新

  • dongyingjiu0669 2013-04-19 22:26
    关注

    On the receiver PHP side $_POST['page_content_1'] will contain data1 and so on.

    评论

报告相同问题?