JQuery Ajax通过URL字符串发送

时间:2013-03-21 13:59:32

标签: php jquery ajax

我似乎遇到了发送一串URL的问题。 URL如下所示:

  

http://www.thewebsitehere.com/mf2/stuff/dirhere.asp?sid=&nm=&type=Publishing&mod=Publions::Article&mid=8F3A7027421F87F791&SiteID=B824D34CAB8727A06DEA3467&tier=4&id=8964A4D50BB59A0AD48594A

它在JS中发送所有信息,但只有当它到达php页面时才会看起来像这样:

  

http://www.thewebsitehere.com/mf2/stuff/dirhere.asp?sid=

我的Ajax设置如下:

jQuery.ajax({
    type: "POST",
    dataType: "html",
    data: "type=add" + "&1A=" + pubName + "&1B=" + postID + "&1C=" + PostTitle + "&1D=" + timeStamp + "&1E=" + pdfLink + "&1F=" + imgLink + "&1G=" + fullArticleLink,
    url: "../wp-content/plugins/visual-editor-custom-buttons/js/wpDataSend.php",
    success: function(results) {
        if (results.indexOf("done") >= 0) {
            showNotifier(8000,'#43d32b','Title, Pub Name, Image, Date, PDF & Article link have been saved!');
        } else {
             showNotifier(8000,'#d32b2b','Could not save... Please try again!');
        }
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
        console.log("Status: " + textStatus);
        console.log("Error: " + errorThrown);
        showNotifier(8000,'#d32b2b','Error: ' + textStatus + ' | ' + errorThrown);
    }
});

我正在从PHP页面收集数据,如下所示:

$newtype     = $_POST['type'];
$pubName     = $_POST['1A'];
$postID     = $_POST['1B'];
$PostTitle     = $_POST['1C'];
$timeStamp     = $_POST['1D'];
$pdfLink     = $_POST['1E'];
$imgLink     = $_POST['1F'];
$Fullarticle   = $_POST['1G'];

我该如何纠正?

3 个答案:

答案 0 :(得分:4)

您可以使用

发送邮件参数the right way
jQuery.ajax({
   ...
   data: {param1 : value1, param2: value2}

答案 1 :(得分:1)

试试encodeURIComponent。这将使URL中的某些字符脱离以符合UTF-8标准。

var encodedURL = encodeURIComponent(str);

答案 2 :(得分:0)

将您的数据更改为:

data: {type: "add", 1A: "pubName"....//and so on},

你必须在价值附近加上引号。