Jquery 中的 MsgBox,将信息传递给 PHP 并检索结果

发布于 2024-11-08 06:03:23 字数 1061 浏览 0 评论 0原文

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

请有人帮助我

// 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

As you can see i am noob at jquery / javascript, i need to pass variable to GET or POST written in form and the result from php need to be passed to jquery, i started to write smthing as below, but it doesnt work.

anyone help me out please

// 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜清冷一曲。 2024-11-15 06:03:23

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

function(data) {
    if (data){
        // inline the data creation/insertion
        $.msgbox($('#textbox').html(data), {type: "info"});
    }
}

$.get is an asynchronous function call, so that means that code below it is not garunteed to be run AFTER it has been proccessed. your callback function inside the $.get call should look like this:

function(data) {
    if (data){
        // inline the data creation/insertion
        $.msgbox($('#textbox').html(data), {type: "info"});
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文