0
這是我的代碼,它的工作原理沒有wordpress。但是放入wordpress中,ajax部分總是失敗。 我有這樣的Ajax,jQuery在wordpress中沒有任何回報
function transtatus_metaboxes(){
if (is_admin() && !trans_parents_zero($GLOBALS["post_info"])){
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://code.jquery.com/jquery-latest.js');
wp_enqueue_script('jquery');
add_meta_box('transtatus_show', 'Translations Status', 'transtatus_show', 'post', 'side', 'high');
}
}
function trans_action_ajax(){
?><!-- jquery ajax function -->
<script type="text/javascript">
<!--
$(function() {
$(".ovalbutton").click(function() {
var val = $(this).attr('href').match(/p=([0-9]+)/)[1];
var val_adi = $(this).attr('href').match(/id=([0-9]*)/)[1];
var str_val = null;
var fnl_val = null;
var dataString = null;
if(val == 1){
str_val = "Require Translation";
} else if(val == 2) {
str_val = "On Progress";
} else if(val == 3) {
str_val = "Completed";
} else {
str_val = "Finialised";
}
fnl_val = str_val + "," + val_adi;
dataString = 'trans_cont_value=' + fnl_val;
$.ajax({
type: "POST",
url: "http://localhost/marcopolowordpress/wp-content/plugins/translation-status/update.php",
data: dataString,
cache: false,
success: function(html){
$('#display').text(" status set to " + str_val);
}
});
alert(dataString);
});
});
//->
</script>
jQuery和AJAX在WordPress那麼這是update.php
<?php
require_once(dirname(dirname(dirname(dirname(__FILE__))))."/wp-config.php");
$q=$_POST["trans_cont_value"];
$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_query("set names ".DB_CHARSET); //solved the unwanted character
mysql_select_db(DB_NAME, $con);
if(isset($q)){
$strarray = explode(',', $q);
$value = $strarray[0];
$id = $strarray[1];
mysql_query("UPDATE MESSAGES SET msg = '$value'");
}
?>
我沒有看到這些代碼的任何問題,但在WordPress不工作。任何幫助? 提前
您的意思是調用帶有URL「localhost」的WordPress的運行時,一個PHP文件升值? – Archer 2012-01-12 10:53:54