/    Sign up×
Community /Pin to ProfileBookmark

Trying to find an alternative way

Hi,

I’ve coded some autocomplete ajax for my own use, and I’ve created a function like this:

[CODE]function doSearch(field, box)
{
$.post(“ajax/phpSide.php”, {phpField: “”+field+””, phpBox: “”+box+””},
function(data)
{
if(data.length >0)
{
$(‘#suggestions’).show();
$(‘#suggestionsList’).html(data);
}
});
}[/CODE]

But for this function to work, I gotta include jquery-1.2.1.pack.js

The only use jquery-1.2.1.pack.js for me in this case is this function and nothing more. I have an onload event on the site and in the pages with jquery-1.2.1.pack.js included, that onload event fails.

I don’t know what is the conflict that jquery-1.2.1.pack.js is making. I was thinking about removing jquery-1.2.1.pack.js and replace it with something more simple which only let me run my function. (I probably have to modify my function)

Can someone help me with this? What to use other than jquery-1.2.1.pack.js and how to modify my own function?

Thanks in advance

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@ssystemsOct 18.2009 — Try this:

[CODE]
function getXmlHttpRequestObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest(); //Mozilla, Safari ...
} else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP"); //IE
} else {
alert("Your browser doesn't support the XmlHttpRequest object.");
}
}

function makeRequest(url, param) {
if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
receiveReq.open("GET", url, true);
receiveReq.onreadystatechange = updatePage;
receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
receiveReq.setRequestHeader("Content-length", param.length);
receiveReq.setRequestHeader("Connection", "close");
receiveReq.send(param);
}

}

function updatePage() {
if (receiveReq.readyState == 4) {
// do the updates here;
}
}

function doSearch(field) {
var url = 'your url';
var postStr = '';
makeRequest(url, postStr);
}

var receiveReq = getXmlHttpRequestObject();
[/CODE]


Just trigger it by whatever event you are using. Hope that helps

Santos Systems
Copy linkTweet thisAlerts:
@asmith20002authorOct 18.2009 — Thanks for the reply mate. I'll try it.

How can I modify this:

$('#suggestions').show(); => document.getElementById('suggestions').style.visibility = 'visible';

$('#suggestionsList').html(data);

how html() will put data into suggestionsList? by appendChild? That won't delete the previous data in it.

any idea?
Copy linkTweet thisAlerts:
@ssystemsOct 18.2009 — You're welcome,


$('#suggestions').show(); => document.getElementById('suggestions').style.visibility = 'visible';
[/QUOTE]


Yes. Exactly like that. For the suggestionsList, try this

[CODE]
document.getElementById('suggestionsList').innerHTML = data;
[/CODE]


from your previous code the variable 'data' is already formatted. If you have issues check the format/value of 'data'.

Good Luck.

Santos Systems
×

Success!

Help @asmith20002 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...