0

I want to load data from an mysql database in javascript.

Part to load the javascript

<script type="text/javascript" src="http://www.domain.de/content/entwicklung/layer.js"></script>

the script itself

// Kampagne laden
//$(document).ready(function() {
//$('#campaign').load('http://www.domain.de/content/entwicklung/campaigns.php');
//});

// Variable für Position festlegen

var left=-200;
var intervalid;  

// Funktion zum erstellen des Layers

function createlayer(content){   
document.writeln(content);
}

// Funktion zum Schließen des Divs

function cdiv(){
document.getElementById("layer").style.display='none'; 
}

// Funktionen zum Bewegen des Layers

function changePos(id){
document.getElementById(id).style.left=left;
} 

function moveIn(id){
if(left>=100){ 
clearInterval(intervalid);
} 
left+=5; 
changePos(id); 
}

function startInterval(id){
intervalid=setInterval("moveIn('"+id+"')",10);
} 


// Content definieren

content= 
'<div id="layer" style="width: 400px; height: 400px; border: 1px solid #404040; margin-left: 100px; margin-top: 50px; position: absolute; z-index:3!important;">'+
'<div style="width: 395px; height: 23px; background-color: lightgrey; padding-left: 5px; padding-top: 2px; border-bottom: 1px solid #404040;">Sponsorenanzeige von <a href="http://www.domain.de" target="_blank">domain.de</a>'+
'<a href="javascript:void(0)" onclick="cdiv();" style="float: right; border: 1px solid black; margin-right: 5px; margin-top: 3px;" title="Fenster schließen" alt="close"><img src="http://www.domain.de/images/close.png"></a>'+
'</div>'+
'<div id="campaign" style="height: 374px; width: 400px; background-color: #0071C1;"></div>'+
'</div>';

// Funktionen aufrufen

createlayer(content);
startInterval('layer'); 

so as seen in this script i allready tried it with some jquery part to load data .. (i get results if i name a variable easy like

$var = '1'; echo $var;

but if i load some data from mysql database.. this data will not shown up

Now i found a script like this

var connection = new ActiveXObject("ADODB.Connection") ;

var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=       <user>;Password=<password>;Provider=SQLOLEDB";

connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");

rs.Open("SELECT * FROM table", connection);
rs.MoveFirst
while(!rs.eof)
{
document.write(rs.fields(1));
rs.movenext;
}

rs.close;
connection.close;

but the problem here ..

connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=       <user>;Password=<password>;Provider=SQLOLEDB";

How do i fill in the right information ? what from this is the host, db-name etc

kind regards

1 Answer 1

2

You should load data via Ajax etc. from a PHP script. JavaScript is public readable and editable - it is a very bad idea to make any database connection / actions there, maybe even with credentials in clear text.


Du solltest die Daten via Ajax von einem PHP-Skript laden. JavaScript-Dateien kann jeder lesen und editieren/manipulieren. Deswegen solltest Du da auf keinen Fall mit der Datenbank agieren, und auch keine Datenbank-Zugangsdaten hinterlegen.

Sign up to request clarification or add additional context in comments.

3 Comments

is there any difference between javascript ajax and jquery ajax ? if i load data with jquery ajax .. i get results (simple echo var) .. but nothing from database ..
jQuery is better syntax and easier.
ok but the problem still exists .. i load data with jquery but i dont get any result from database .. so i dont know what to change else ..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.