Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
向JQuery Ajax调用传递参数_Jquery_Jquery Ui - Fatal编程技术网

向JQuery Ajax调用传递参数

向JQuery Ajax调用传递参数,jquery,jquery-ui,Jquery,Jquery Ui,我不熟悉JQuery。我已经了解了如何进行AJAX调用,以及如何创建成功或失败的回调函数。不过,我很难弄清楚如何传递参数。以下是我的JQUery代码: $(document).ready(function(){ $('#submit_new_admin').click(function() { $.ajax({ type: 'POST', url: '[mu_url]/process_request.php', data: { reques

我不熟悉JQuery。我已经了解了如何进行AJAX调用,以及如何创建成功或失败的回调函数。不过,我很难弄清楚如何传递参数。以下是我的JQUery代码:

$(document).ready(function(){
$('#submit_new_admin').click(function() {

    
    $.ajax({
      type: 'POST',
      url: '[mu_url]/process_request.php',
      data: { request: 'add_new_admin' },
      beforeSend:function(){
        $('#ajax-panel').html('<div class="loading"><img src="/images/loading.gif" alt="Loading..." /></div>');
      },
      success:function(data){
      alert('ok')'
      },
      error:function(){
        $('#ajax_response').html('<p class="error"><strong>Oops!</strong> Try that again in a few moments.</p>');
      }
    });
}); 
});

我如何才能做到这一点?

您可以使用jquery来填充动态值- e、 g.数据:
{firstname:$('#firstname').val(),…}

但是,由于您有一个hugh表单,因此可以使用jquery表单序列化API通过ajax调用将所有表单元素作为url或数组传递,而不是填充单个元素

e、 g.
$.post(“test.php”,$(“#testform”).serialize())


更多信息,请参见&

“content”是一个可以传递到ajax调用中的参数,“this”则指“content”的内容。

谢谢,Jayendra!我使用了serialize,它工作得非常好!
    <form name="" action="" method="post">
        <select name="user_level">
            <option value="1">Full Admin</option>
            <option value="2">Junior Admin</option>
        </select><br/><br/>
        <label for="firstname">Firstname</label>  <input type="text" name="firstname"><br/><br/>
        <label for="lastname">Lastname</label>  <input type="text" name="lastname"><br/><br/>
        <label for="username">Username</label>  <input type="text" name="username"><br/><br/>
        <label for="fb_id">FaceBook ID</label>  <input type="text" name="fb_id"><br/><br/>
        <label for="password">Password</label>  <input type="password" name="password"><br/><br/>
        <label for="password_conf">Enter Password Again</label>  <input type="password" name="password_conf"><br/><br/>
        <input type="hidden" name="submitted">
        <input id="submit_new_admin" type="button" value="Add As Admin">
    </form>
data: { request: 'add_new_admin', firstname: [firstname value from form], lastname: [lastname value from form], username: [username from form]} and so on.