简体   繁体   English

页面上的jQuery框在php上加载

[英]Jquery box on page load on php

I have a form where users can save activity of the day, with date and time.(index.php). 我有一个表单,用户可以在其中保存日期和时间的一天的活动。(index.php)。 I have build a jquery that opens a dialog popup window on page load...I want to include this code in my second php page. 我建立了一个jQuery,可以在页面加载时打开对话框弹出窗口...我想将此代码包含在第二个PHP页面中。 This page is called add.php. 此页面称为add.php。 the user go there when he press a submit button in page index.php. 当用户按下页面index.php中的“提交”按钮时,用户就去了那里。 When he press the submit button, to add an activity and exist an activity in that time and date I want to show a popup. 当他按下提交按钮时,要添加一个活动并在那个时间和日期存在一个活动,我想显示一个弹出窗口。 But how can I include the popup below in the add.php. 但是如何在add.php中包含以下弹出窗口。

My code is below 我的代码如下

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/start/jquery-ui.css"
    rel="stylesheet" type="text/css" />
<script type="text/javascript">
    $(function () {
        $("#dialog").dialog({
            title: "jQuery Dialog Popup",
            buttons: {
                Close: function () {
                    $(this).dialog('close');
                }
            }
        });
    });
</script>
<div id="dialog" style="display: none">
    You have an activity on this time
</div>

And this is add.php 这是add.php

<?php
$con = mysql_connect('127.0.0.1','root','');
if (!$con)
  {
  die('<div class="content">Lidhja me databazen nuk mund te kryhet</div>' .mysql_error(). ' </body></html>');
  }
if(!mysql_select_db("Axhenda",$con))
die('<div class="content">Nuk mund te hapet databaza Axhenda</div>'.mysql_error(). '</body></html>');



$Data=$_POST['date'];
$Ora=$_POST['time'];
$Emri=$_POST['emritakimit'];
$Pershkrimi=$_POST['pershkrimi'];

session_start();


if (!isset($_SESSION['user_id'])){

header('location:index.php');
}

//variabli SESSION per te ruajtur ID e perdoruesit
$perdoruesi=$_SESSION['user_id'];

$selekto=mysql_query("SELECT * FROM aktiviteti WHERE Data='$Data' and Ora='$Ora'");

$nr_rreshtave=mysql_num_rows($selekto);

if ($nr_rreshtave>0)
{   
    //here I want to include the function above


header('locationindex.php');}


    else
    {


$query ="INSERT into aktiviteti VALUES('', '$perdoruesi', '$Emri', '$Pershkrimi' ,'$Data','$Ora')";


$result=mysql_query($query,$con);






if($result)

{   header('location:index.php?error-akt1=1');}

else

{   header('location:index.php?error-akt2=1');}}

mysql_close($con);

?>

please help me...Thanks in advance 请帮助我...谢谢

You actually want the pop up to show up only if there is an error, in which case add.php redirects to an URL with error-akt1=1 or error-akt2=2 as parameter. 实际上,您实际上希望弹出窗口仅在出现错误时才显示,在这种情况下,add.php重定向到以error-akt1=1error-akt2=2作为参数的URL。 If you added the pop up to add.php, it would break the redirects. 如果将弹出窗口添加到add.php中,则会中断重定向。 Therefore, you need to do it on index.php instead, but ONLY if the parameters are loaded. 因此,您需要改为在index.php上执行此操作,但仅在加载参数时才需要。

To make the parameters available, to you, use the code provided by BrunoLM in this post: How can I get query string values in JavaScript? 为了使参数可用,请使用本文中BrunoLM提供的代码: 如何获取JavaScript中的查询字符串值? (or any other code in that post, but BrunoLM provided one in jQuery, instead of pure Javascript). (或该帖子中的任何其他代码,但BrunoLM在jQuery中提供了一个,而不是纯Javascript)。 I'm copying the main part here: 我在这里复制主要部分:

(function($) {
    $.QueryString = (function(a) {
        if (a == "") return {};
        var b = {};
        for (var i = 0; i < a.length; ++i)
        {
            var p=a[i].split('=');
            if (p.length != 2) continue;
            b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
        }
        return b;
    })(window.location.search.substr(1).split('&')) })(jQuery);

Get the querystrying by putting: 通过输入以下内容来获取查询结果:

$.QueryString["param-name"]

And once you have the parameter, just use an if statement around the loading of your alert, like so: 一旦有了参数,就可以在警报加载周围使用if语句,如下所示:

$(function () {
   var error-akt1 = $.QueryString["error-akt1"];

   if (error-akt1 == 1) {
        $("#dialog").dialog({
            title: "jQuery Dialog Popup",
            buttons: {
                Close: function () {
                    $(this).dialog('close');
                }
            }
        });
   }
});

Repeat for error-akt2 or, even better, use error-akt=1 or error-akt=2 to send different erro r messages in the same parameter and querystring variable. 对error-akt2重复,甚至更好,使用error-akt=1error-akt=2在相同的参数和querystring变量中发送不同的error-akt=2消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM