JQuery or Ajax Script Help?
I want something that when you click a link it changes the database fetch method from: mysql_query(“SELECT * FROM posts ORDER BY post_id DESC ;”);
to:
mysql_query(“SELECT * FROM posts ORDER BY post_likes DESC ;”);
The page is allowed to reload, but nothing in the URL is allowed to change. You could make it change the value of a variable. Like on click it changes $sort to post_likes instead of post_id.
I just need help, should be easy.
- Category: JQuery Questions
I want something that when you click a link it changes the database fetch method from: mysql_query(“SELECT * FROM posts ORDER BY post_id DESC ;”);
to:
mysql_query(“SELECT * FROM posts ORDER BY post_likes DESC ;”);
The page is allowed to reload, but nothing in the URL is allowed to change. You could make it change the value of a variable. Like on click it changes $sort to post_likes instead of post_id.
I just need help, should be easy.
Other Questions
Login
Search
Recent Comments
- dgdg_dasdad on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- Anas Imtiaz on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- David D on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- Wolfman on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- TnT on Having a Jquery PHP problem?


Neneng_Questionaire
Posted 9 months ago
You’ll need two webpages.
1. The ‘display’ page (can by static (.html) or dynamic (.asp, .aspx, .php), doesn’t matter)
2. The ‘transactional’ page (must be dynamic)
The display page will have a DIV or SPAN tag or whatever tag that has an “innerHtml” property.
It should look something like this:
display page
function newAjax() {
var initAjax;
try {
initAjax = new ActiveXObject(‘MSXML2.XMLHTTP’);
} catch (e) {
try {
initAjax = new ActiveXObject(‘Microsoft.XMLHTTP’);
} catch (e) {
try {
initAjax = new XMLHttpRequest();
} catch (e) {
initAjax = null;
}
}
}
if (initAjax == null) {
window.alert(“ERROR”);
} else {
return initAjax;
}
}
function getResponse(query) {
var ajaxInstance = newAjax();
ajaxInstance.onreadystatechange = function() {
if(ajaxInstance.readyState == 4) {
if(ajaxInstance.status == 200) {
document.getElementById(“TARGET”)
.innerHTML = ajaxInstance.responseText;
} else {
document.getElementById(“TARGET”)
.innerHTML = “ERROR”;
}
}
}
ajaxInstance.open(“GET”,
“transactional.aspx?query=” + query, true);
ajaxInstance.setRequestHeader(“Content-type”,
“application/x-www-form-urlencoded”);
ajaxInstance.send(null);
}
The display page serves as the user interface.
The transactional page on the other hand will be called by the display page.
It should look something like this:
//transactional.aspx
public string connStr= “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=”
+ AppDomain.CurrentDomain.BaseDirectory
+ “test.mdb;Jet OLEDB:Database Password=test;”;
public OleDbConnection oleConn;
public OleDbCommand oleCmd;
public OleDbDataReader oleDr;
public OleDbDataAdapter oleDa;
public string getParam(string paramName)
{
string s = string.Empty;
if (Context.Request.Form.Count != 0)
{
s = Convert.ToString(
Context.Request
.Form[paramName]);
}
else
{
if (Context.Request.QueryString.Count != 0)
s = Convert.ToString(
Context.Request
.QueryString[paramName]);
}
return (s == null) ? string.Empty : s.Trim();
}
void Page_Load(Object sender, EventArgs e)
{
string query = Server.UrlDecode(getParam(“query”));
if (query == “Query1″)
sql = “SELECT * FROM table1″;
else if (query == “Query2″)
sql = “SELECT * FROM table2″;
oleConn = new OleDbConnection(connStr);
oleConn.Open();
oleCmd = new OleDbCommand(sql, oleConn);
oleDr = oleCmd.ExecuteReader();
string result = string.Empty;
while (oleDr.Read())
{
for (int y = 0;
y < oleDr.FieldCount;
y++)
{
result += "|"
+ oleDr.GetValue(y).ToString()
+ "|";
}
result += "”;
}
oleDr.Close();
oleDr.Dispose();
oleCmd.Dispose();
oleConn.Close();
Response.Write(result);
}
I hope this gave you an idea.
Good luck!