1

如您所见,我是 jquery / javascript 的菜鸟,我需要将变量传递给以表单形式编写的 GET 或 POST,并且需要将 php 的结果传递给 jquery,我开始如下编写 smthing,但它不起作用。

任何人都请帮帮我

// id and settings for msg box

$("#registerin").click(function() {
  $.msgbox("<p>In order to process your request you must provide the following:</p>", {
    type    : "prompt",
    inputs  : [
      {type: "text",label: "Insert your Name:", value: "George", required: true},
    ],
    buttons : [
      {type: "submit", value: "OK"},
      {type: "cancel", value: "Exit"}
    ]
  }, // id and settings for msg box - end
   function(name) {
    // checking if name field has been set
    if(name) {
    // pass from field to php $_GET['name_php'] variable
      $.get("form.php", {name_php: name },
**// rewriten**
    function(data) {
    if (data){
        // inline the data creation/insertion
        $.msgbox($('#textbox').html(data), {type: "info"});
    } // if data end
  }); // function data end
**// rewriten**
    } // if name end
  }); // function name end

}); // registerin click
4

1 回答 1

0

$.get是一个异步函数调用,因此这意味着它下面的代码在它被处理之后不会被运行。调用中的回调函数$.get应如下所示:

function(data) {
    if (data){
        // inline the data creation/insertion
        $.msgbox($('#textbox').html(data), {type: "info"});
    }
}
于 2011-05-18T15:20:03.353 回答