小编Ech*_*ara的帖子

AJAX:XMLHttpRequest中beforeSend函数的等价函数是什么

在 $.ajax 中有 beforeSend 函数,但现在我正在尝试使用 XMLHttpRequest,我在 $.ajax 中寻找与 beforeSend 等效的函数。我如何在这里实现它。

这是我的 xhr 代码,

xhr = new XMLHttpRequest();
    var url = '../ajax/ajax_edit/update_ajax_staffUser.php';

    if(file.files.length !== 0){

        if(!check(fileUpload.type)){
            alert("This file format not accepted");
            return false;
        }
        xhr.open('post', url+param, true);
        xhr.setRequestHeader('Content-Type','multipart/form-data');
        xhr.setRequestHeader('X-File-Name', fileUpload.name);
        xhr.setRequestHeader('X-File-Size', fileUpload.size);
        xhr.setRequestHeader('X-File-Type', fileUpload.type);
        xhr.send(fileUpload);
    }else{
        xhr.open('post', url+param, true);
        xhr.setRequestHeader('Content-Type','multipart/form-data');
        xhr.send(fileUpload);
    }


    xhr.onreadystatechange = function(e){
        if(xhr.readyState===4){
            if(xhr.status==200){
                $('.bounce_dim').show();
                setTimeout(function(){
                    $('.trigger_danger_alert_changable_success').show().delay(5000).fadeOut();
                    $('#palitan_ng_text_success').html('User successfully modified');
                    $('#frm_edit_staffUser')[0].reset();
                    $('#modal_staff').modal('hide');
                    $('.bounce_dim').hide();
                },1000);
                getUserStaffTable();
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

由于用户正在将图像上传到我的网站,我需要在调用之前制作一个等待界面,因为图像尺寸太大。

javascript ajax jquery xmlhttprequest

4
推荐指数
1
解决办法
9217
查看次数

PHP:在Array中分隔2个或更多1个键的值

我有阵列来自我的ajax

$contestant_name_arr = $_GET['contestant_name_arr'];
print_r($contestant_name_arr);
Run Code Online (Sandbox Code Playgroud)

每当我尝试获取每个循环的值时,我得到错误,因为而不是这个

Array ( [0] => value1,value2 )
Run Code Online (Sandbox Code Playgroud)

它应该是这样的:

Array ( 
    [0] => value1 
    [1] => value2
)
Run Code Online (Sandbox Code Playgroud)

我如何在上面的例子中分开.

php arrays

3
推荐指数
1
解决办法
47
查看次数

PHP:检查 URL 末尾是否包含斜杠

我正在使用模型视图控制器,并且在我的 URL 中,我需要在 URL 的末尾添加斜杠。如何检查它是否有斜线?

http://localhost/tabulation/event/event_name/<--I need to check this slash

$url = isset($_GET['url']) ? $_GET['url'] : null;
$url = rtrim($url. '/');
$url = explode('/', $url);
//if($url[2] has no backslashes then execute the condition
Run Code Online (Sandbox Code Playgroud)

php model-view-controller

3
推荐指数
1
解决办法
4429
查看次数