-1

I have this code in PHP. I want to convert the syntax to JavaScript. Could you help me?

$id = "";
$auth_token = "";
    if (preg_match("/&id\=([^&]+)/", $profile_url, $matches)):
    $id = $matches[1];
    preg_match("/&authToken\=([^&]+)/", $profile_url, $matches);
    $auth_token = $matches[1];
endif;

I've tried this code:

var name, publicUrl, location, industry, company, position, inviteUrl, idToken, authToken;

        $('input:checked').each(function () {
            name = $(this).closest('tr').find('td.publicUrl a').text();
            location = $(this).closest('tr').find('td.location').text();
            industry = $(this).closest('tr').find('td.industry').text();
            company = $(this).closest('tr').find('td.company').text();
            position = $(this).closest('tr').find('td.position').text();
            publicUrl = $(this).closest('tr').find(' td.publicUrl a').prop('href');
            inviteUrl = $(this).closest('tr').find('td.inviteLink a').prop('href');
            inviteUrl = text.match(/&id\=([^&]+)/);
            idToken = match[1];
        });

        alert(idToken);

It doesnt alert anything at all.

This is the error. I can't understand the error because I already declared it and it has value:

Error Problem

4

1 回答 1

0

您可以试试这个(获取和的查询字符串keyauthToken

var str = "http://www.linkedin.com/people/invite?from=profile&key=211773644&authToken=88_h&authType=name%22";

var key = str.match(/key=([^&]+)/);
console.log(key[1]); // 211773644

var auth = str.match(/authToken=([^&]+)/);
console.log(auth[1]); // 88_h

演示。

于 2013-09-20T19:49:51.523 回答