weixin_33717298 2014-05-20 07:01 采纳率: 0%
浏览 40

带有JavaScript的Ajax代码

I have null experience in web programming, yet I am testing a simple add on to work with my app. On the webpage I display a number of rows. Each row has an editable field that the user needs to input.

Once he inputs it, I want to launch PHP code to run an SQL statement. My initial try worked, yet the page of the php script was opened. I would like somehow the php to run in the background and the user stays on the same page.

Looking online I found that I need to have something like the following:

<script>
function DataChanged(mId,mQ){
        document.getElementById('demo').innerHTML = 'Change Id='+mId+'Q='+mQ ;
        $.ajax({
                url: 'submitChange.php?Id=5'
                });

        document.getElementById('demo').innerHTML = 'Arrived here?';
}
</script>

The text field is changed to:

Change Id=...

yet the script isn't running and text isn't becoming

"Arrived here?"

I ran the submitChange.php?Id=5 separately and it worked, so I am guessing my error is from the script above. Any idea what could be wrong?

  • 写回答

4条回答 默认 最新

  • ~Onlooker 2014-05-20 07:06
    关注

    You are trying to use jQuery $.ajax to achieve this, what you are looking for is an XMLHTTPRequest

    评论

报告相同问题?