Jump to content

Recommended Posts

There are only a few things I can think of to even get the URL in JQuery, let alone get data from it. Perhaps you can somehow modify this:

<!-- Full URL http://domain.com/file.whatever?anyvar=something -->

<script type="text/javascript">
alert($(location).attr('href'));
</script>

 

Your second question however makes no sense. I assume you want to access php sessions in your JQuery? In which case it should work just putting in the source code.

 

<?php
session_start();
$_SESSION['uid'] = "23123";
?>

<!-- other stuff -->

<script type="text/javascript">
<?php
echo "var stuff= '".$_SESSION['uid']. "';";
?>
alert('Err...hi? '+stuff+' ');
</script>

Situation:

i have 2 mysql table`s

1. tbl_document (id, number_of_document)

2. tbl_items_of_document (id, name_of_item, document_id, user_id)

 

now, clasic php html form

 

<form action="insert.php?document_id=<?php echo $id; ?>" method="post">
.....
</form>

 

after form we use

 

$document_id = $_GET["document_id"];
$name = $_POST["name_of_item"];
//...
mysql_query("INSERT INTO `tbl_items_of_document` SET `name_of_item` = '$name', `document_id` = '$document_id', `user_id` = '$user_id'")or die(mysql_error());

 

we have all necessary data inserted in the table

 

And the we come to problem if we want to use jquery

 

with code below, i can insert data in one independet mysql table

jQuery Basics: POST/GET Data (HTTP Request)

 

index.php

[/size][/font][/color]
<input type="text" id="name" />
<div id="name_feedback"></div>
[color=#000000][font=Tahoma, Verdana, Arial][size=3]

 

jfunc.js

[/size][/font][/color]
$('#name').keyup(function(){
var name = $('#name').val();
$.post('proces.php'), {name:name}, function(data) {
$('#name_feedback').html(data);
});

});
[color=#000000][font=Tahoma, Verdana, Arial][size=3]

 

proces.php

[/size][/font][/color]
<?php
if(isset($_POST['name'])){
$name = $_POST['name'];
echo $name; //or mysql_query.....
[color=#000000][font=Tahoma, Verdana, Arial][size=3]

 

and this code is ok for insert into independent table

 

what if we have relation database, with two tables?

1. tbl_document (id, number_of_document)

2. tbl_items_of_document (id, name_of_item, document_id, user_id)

 

and i want to insert data into tbl_items_of_document, and i nead for that:

- value of `id` from tbl_document

- and value of `session`

 

how to GET `id` of the document to write in to `tbl_items_of_document` with jQuery,

or,

how to GET session id with jquery, becose i want to know who create that item or item`s?

 

thanks

This function will do it for you:

function getGet(name)
   {
       var regexS, regex, results;

       name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
       regexS = "[\\?&]" + name + "=([^]*)";
       regex = new RegExp(regexS);
       results = regex.exec(documentSrc);

       if(results !== null)
       {
           return decodeURIComponent(results[1].replace(/\+/g, " "));
       }

       return false;
   }

 

So if your URL is www.example.com?key=value, you can get $_GET['key'] using:

getGet(key);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.