dqcd84732 2016-05-04 21:46
浏览 55

通过Javascript调用php文件

I currently have this code below working A-OK, it basically loads up a pretty notification box with a message on a onClick event, so when a user presses the button then the notification pops :

<button id="buttonsuccess" class="btn btn-success" onClick="FunctionSuccess()">button</button>

<script>
function FunctionSuccess(){
Lobibox.notify('success', {
iconSource: 'fontAwesome',
size: 'mini',
delay: 8000,
sound: false,
title: 'Success!',
msg: 'Success message here.'
});
}
</script>

However, I would like to run a PHP file on the onClick event. My code to run the PHP file within the Javascript code is as follows:

<button id="buttonsuccess" class="btn btn-success" onClick="FunctionSuccess()">button</button>

    <script>
    function FunctionSuccess(){

$.ajax({
    url: '/copy/test.php'
})

Lobibox.notify('success', {
iconSource: 'fontAwesome',
size: 'mini',
delay: 8000,
sound: false,
title: 'Success!',
msg: 'Success message here.'
});
}
</script>

But this doesn't work. I actually get the notification box message as I did before, but the PHP code does not run. Instead, I get the following error on console:

GET http://domain.com/copy/test.php 500 (Internal Server Error)

I just need to execute the code within the test.php file, I don't need to get data from it or post data to it, just execute the PHP file. BTW, I've tested the PHP file, it works fine.

error_log shows no errors, no PHP errors either. The permissions on the php file is also OK.

Much appreciate any insight you may be able to provide.

Thanks.

  • 写回答

2条回答 默认 最新

  • dousong1926 2016-05-04 21:51
    关注

    (Assuming you're using chrome..)

    Check your console, and enable 'LogXMLHTTPRequests' if it isn't checked.

    When you click the button, you should see the url being called in the console. Right click on that, and open in a new window.

    Chances are, the wrong domain is coming up, or there's an error in the php code.

    You can also open the console and select the network tab. If you have a request that generated a 500, it'll appear red, you can right click on that line, select 'copy response' and paste that into your favorite text editor.

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line