problem with php dom xpath
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.
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.
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.
精彩评论