Jquery,如何设置数组键?

时间:2016-12-05 21:05:44

标签: php jquery ajax

如何在数组jquery中设置键?

RtlIsLongPathAwareProcessByManifest

当我尝试

BOOL CreateFolder(LPCWSTR lpPathName)
{
    return CreateDirectoryW(lpPathName, 0) || GetLastError() == ERROR_ALREADY_EXISTS;
}

void LPT()
{
    // check manifest and registry

    BOOLEAN bByManifest = 0, bLongPathsEnabled = 0;

    if (HMODULE hmod = GetModuleHandle(L"ntdll"))
    {
        BOOLEAN (NTAPI * RtlIsLongPathAwareProcessByManifest)();
        BOOLEAN (NTAPI * RtlAreLongPathsEnabled)();

        if (*(FARPROC*)&RtlIsLongPathAwareProcessByManifest = GetProcAddress(hmod, "RtlIsLongPathAwareProcessByManifest"))
        {
            bByManifest = RtlIsLongPathAwareProcessByManifest();
        }

        if (*(FARPROC*)&RtlAreLongPathsEnabled = GetProcAddress(hmod, "RtlAreLongPathsEnabled"))
        {
            bLongPathsEnabled = RtlAreLongPathsEnabled();
        }
    }

    WCHAR name[128], path[0x8000], *c;

    if (bLongPathsEnabled && bByManifest)
    {
        // hung test in GetTempPathW

        __stosw((PUSHORT)path, 'x', MAX_PATH + 1);
        path[MAX_PATH + 1] = 0;

        if (SetEnvironmentVariable(L"TMP", path))
        {
            // hung here in infinite loop by windows error

            // ---> buffer allocated on sizeof(WCHAR) less than required, 
            // |    got STATUS_BUFFER_TOO_SMALL
            // | -< free buffer
            GetTempPathW(RTL_NUMBER_OF(path), path);// never return :)
        }
    }

    if (!SHGetFolderPath(0, CSIDL_PROFILE , 0, 0, path))
    {
        *name = '\\';
        __stosw((PUSHORT)name + 1, '3', RTL_NUMBER_OF(name) - 2);
        name[RTL_NUMBER_OF(name) - 1] = 0;

        c = path + wcslen(path);

        int n = 4;
        do 
        {
            memcpy(c, name, sizeof(name));
            c += RTL_NUMBER_OF(name) - 1;

            if (!CreateFolder(path))
            {
                break;
            }

        } while (--n);

        if (!n)
        {

            wcscpy(c, L"\\1.txt");

            HANDLE hFile = CreateFileW(path, FILE_GENERIC_WRITE, FILE_SHARE_VALID_FLAGS, 0, OPEN_ALWAYS, 0, 0);

            if (hFile != INVALID_HANDLE_VALUE)
            {
                CloseHandle(hFile);
                return ;
            }
        }
    }

    GetLastError();
}

1 个答案:

答案 0 :(得分:0)

正如Charlotte Dunois在JavaScript中提到的,有数组和对象(PHP允许关联数组,但它们在JavaScript中不存在),如果你想使用formdata [0-5]那么你可以访问的例子您需要使用对象的密钥:

var formdata = {
    name: $('input[name=name]').val(),
    surname: $('input[name=surname]').val(),
    yob: $('input[name=year_of_birth]').val(),
    cob: $('input[name=city_of_birth]').val(),
    university: $('input[name=university]').val(),
    insuranceNumber: $('input[name=insurance_number]').val() 
}

如果您正在使用JSON(如果您不是我会建议使用该路由),一旦您发送ajax请求并将其放在PHP端,您可以使用json_decode将其转换为基于首选项的对象或关联数组:

$arr = json_decode($_REQUEST['requestData'], true) //associative array $arr['formdata']['key']
$obj = json_decode($_REQUEST['requestData']) //object $arr->formdata->key

当您使用json_encode时,甚至PHP都会将关联数组转换为对象。这是因为关联数组并不总是PHP之外的对象所在。