drccfl9407 2013-08-20 00:03
浏览 44

从ajax javascript调用php

I have a PHP-based template website that has been heavily modified.

I am in the process of adding some RSS feeds, most of which are easy to "interpret" and display satisfactorily but one is in caps with "pre" formatting as well.

I want to modify the content. I look at all the mods I make as education and invariably am able to google satisfactory solutions to the problems I come across but, despite an earlier extensive programming background, without a thorough grounding in Javascript, Ajax, PHP, CSS and HTML, there are sometimes things that just frustrate the hell out of me.

All I want to do is pass a block of text from javascript code to PHP code, massage it and get the result back. I am at a point in a ajax/jscript function where...

items[i].content

...contains the block of text that I want massaged and I have a piece of code that I got from here, I think, that ostensibly calls the PHP code...

function compute() {
    var params="session=123";
    $.post('wxspellch.php',params,function(data){ 
        alert(data);//for testing if data is being fetched
        var myObject = eval('(' + data + ')');
        document.getElementById("result").value=myObject(addend_1,addend_2);
    }); 

...and, unfortunately, it isn't documented so I don't have a clue what has to be customized. All I have done so far is enter the name of my PHP script. The PHP script is written like this...

$pspell = pspell_new('en','american','','utf-8',PSPELL_FAST);
function spellCheckWord($word) {
    global $pspell;
    $autocorrect = TRUE;
    // Take the string match from preg_replace_callback's array
    $word = $word[0];
    etc......
}
function spellCheck($string) {
    return preg_replace_callback('/\b\w+\b/','spellCheckWord',$string);
}
echo spellCheck("...... the data   .......")

The PHP tests out fine with hard-coded data. I just need to know what further customizing I have to do to the javascript and php in order to facilitate the passing and recovery of the block of text.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)