0

I have a snipet of html code,in client side, I use Jquery to modify some dom element's content(pure text). and now I want to update the modifed text to the server as well.

what I am trying to do is to compute the modified element's xpath in client side, and send it to server along with new content. the xpath will look something like" /div/div[2]/table/tr/td[2]..." but I don't know how to make use of this path with php Dom xpath.

any guidance/suggestions will be appreciated.

3
  • In essence you want to tell PHP which data item it needs to update. Is this the simplest way you can do this? Don't you have any restrictions on which data items can be updated you can use to simplify the situation? Commented May 8, 2011 at 11:55
  • that is right, I need to tell php which data needs updating. Commented May 8, 2011 at 12:12
  • there is no tight restrictions acturally, any content could be updated. but updating tags is very rare. Commented May 8, 2011 at 12:14

2 Answers 2

1

Why don't you want to use the jQuery to send modifications to PHP?

It will be simpler as you are already using jQuery to modify content. At the end of your snippet add following method

$.post('path/to/php-file.php', {
    nameOfVar1 : 'valueToSend',
    nameOfVar2 : varToSend
}, function (data) {
    /* What to do on success */
});

You can read more about it here http://api.jquery.com/jQuery.post/

Example:

You can write single function to handle everything. Of course you can use other approach which is more suitable in your context. Sample function would be:

function updateContent(content, table, column) {
  $.post('update.php', {
    content : content,
    tableName : table,
    columnName : column
  });
}

And the call the functions whenever you need it. You will pass $('#element').text() as content. On the server side you will use following SQL to update your contents:

$sql = "UPDATE $_POST['tableName']
        SET $_POST['columnName']=$_POST['content']";

Of course this is pure example and server side code is not safe for SQL injections. You must check posted values and escape string.
You can use this example to build javascript functions which will be more appropriate for your context.

Sign up to request clarification or add additional context in comments.

9 Comments

Hi, thank you very much for your reply. Maybe I wasn't clear. I need to send mofidified content to server because I need to update the content in the database as well. I use the $.post to send the xpath and new content actually.
Sorry but I haven't got your point again. You can update the content in the database using the same $.post. Send content to server-side script and update the database. There is no limit on content size. I don't get why are you using xPath at all...
yes. that would be a solution. but I am thinking if I only update a few strings, it would not be efficient to send the whole document back to server. besides I would like to record where in the content has been modified over times. I hope this is clear. Best.
Hope got your problem right. So you are updating content in <p id="phrase"> Content here </p> for example. You are using jQuery to do it $('#phrase').html('new content here') or $('#phrase').text('again content') and now you want to update the value in DB. Why dont you just use the write 1 function to do all post. Examples you can see on the post. (I'm editing it)
yes, exactly,you got my point. I am sorry, what is write 1 function??
|
0

I compute the position of each path like 1 3 4 2 4 and send the path to server, correspondingly server find find the position using the path.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.