weixin_33743248 2016-01-17 18:24 采纳率: 0%
浏览 42

Wordpress Ajax网址…不发送

I have a javascript file that is trying to send POST data to a php file that is in a directory above it in my filesystem:

plugin 
|js
 /script.js
|saveData.php

script.js:

$.ajax({
 type: "POST",
 url: '/../saveData.php',
    data: {
        obj 
    }, //send data if needed
    success:function(){
        alert("OK sent data!");
    }

This however, doesn't seem to work. How should I be referencing this file? I am also a little bit confused as to where this php file should reside to begin - I need to be able to make calls to the $wpdb class. Any help/advice appreciated!

  • 写回答

2条回答 默认 最新

  • weixin_33738578 2016-01-18 08:35
    关注

    The URL needs to be relative to the HTML document the JS is running inside, not to the JS file itself.

    If it did need to be relative to the JS file then you would want ../saveData.php. Starting with a / goes back to the root of the webserver (and then the ../ tries to go up a level from there, which is impossible, so that bit is ignored).

    评论

报告相同问题?