PHP和NodeJS与mongodb

I try to save a Steamtrade URL in my mongodb but it doesn't work. If i try to save it, it just disappears and tells me to enter it again. I think there's a problem with one of these parts:

$(document).on('click', '.save-link', function() {
var link = $('input[rel="get-trade-link"]').val();
var escapedLink = escape(link);
if (link.indexOf('https://steamcommunity.com/tradeoffer/new/?partner=') < 0 && link.indexOf('token') < 0) {
    $('#error').show('fast').delay(1600).hide('fast');
    $('#error').html('<strong>Error: </strong>Enter Correct Url And Try Again!');
} else {
    var data = 'link=' + escapedLink;
    $.ajax({
        type: 'POST',
        url: '/ajax/tradelink.php',
        cache: false,
        data: data
    });
    $('#success').show('fast').delay(1600).hide('fast');
    $('#success').html('<strong>Link Successfully Saved. </strong>Dont Forget To Open Inventory To Receive winnings!');
    $('.token-block.promo').addClass('hidden');
} });

The tradelink.php is here:

    <?php 
session_start();
include ('../steamauth/userInfo.php');
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
if(!isset($_SESSION['steamid'])) {
exit();
}
$userLink = $_POST['link'];
$userLink = addslashes($_POST['link']);
$m = new MongoClient();
$db = $m->selectDB('admin');
$collection = new MongoCollection($db, 'users');

// search for fruits
$fruitQuery = array('steamid' => $steamprofile['steamid']);

$cursor = $collection->find($fruitQuery);
foreach ($cursor as $doc) {
     $tradeLink = $doc['tradelink'];
}

if($tradeLink == '') {
    echo 'No entry found!';
    $person = array("steamid" => $steamprofile['steamid'], "tradelink" => "".$userLink."" , "type" => 'trade-link');
    $collection->insert($person);
}
else {
    echo 'Record found!';
    $obj = $collection->findOne();

    $update = array('tradelink' => "".$userLink."");

    $collection->update(
    array( 'steamid' => $steamprofile['steamid'] ),
    array( '$set' => $update )
);
}
}
 ?>
dongtiannan0367
dongtiannan0367 node.js在服务器端使用javascript,而不是php...我对你的设置感到困惑。
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问