AJAX call problem
AJAX call problem
Hi there,
I have a webpage where I have two forms ..one form is to create new help desk ticket and on the same page i have another form in which user can see the status of the entered ticket by putting the ticket number and press the submit button.
For this i am using a javascript file ..following is the code
-
$(function() {
//---------- Page load defaults ----------------
$("#sucessbox").hide();
//Submit new ticket button Process
$("#submitticket").click(function() {
// validate and process form here
var subject_value = $("input#subject").val();
var msgbody_value = $("textarea#message").val();
if (subject_value == "")
{
// alert("Subject is required....");
alert("Subject is a required field...");
$("input#subject").focus();
return false;
}
if (msgbody_value == "")
{
alert("Please provide some text here as it's required...");
$("textarea#message").focus();
return false;
}
//Pre-Ajax Call stuff performs here
//Create parameters for form processing
var thefields = collectFields();
//Set record status to add new ticket
document.getElementById('recstatus').value = 'I';
//Perform Ajax stuff from here
//--------------------------------------- Begin of Ajax Code ------------------------------------------------------
//Create string parameter list
var dataString = thefields+"&recstatus="+document.getElementById('recstatus').value;
$.ajax({
type: "GET", //GET Method used instead of POST
url: "ticketdata.php", //php file that processes the data
data: dataString, //Pass the data
cache: false, //Do not cache the page
success: function(returnString)
{
if(returnString == "Success")
{
$('#welcome').hide();
$('#openBox').hide();
$('#vstatus').hide();
$("#sucessbox").fadeIn("slow");
return true;
}
}
});
return false;
//--------------------------------------- End of Ajax Code ---------------------------------------------------------
}); //-----------------------------------------End of Submit button code -------------------
//------------------------ View Ticket Button Process ----------------------------------------
$("#viewticket").click(function() {
//Set record status to View ticket
//document.getElementById('recstatus').value = '';
document.getElementById('recstatus').value = 'V';
alert('good so far..');
//Verify current ticket no. using AJAX
var dataStr = "recstatus="+document.getElementById('recstatus').value;
$.ajax({
type: "GET", //GET Method used instead of POST
url: "testphp.php", //php file that processes the data
data: dataStr, //Pass the data
cache: false, //Do not cache the page
success: function(abc)
{
if(abc== "1")
{
alert("Acting normally......");
//return false;
}
else
{ alert("Serious problem here..."); return false;
}
}
}); // -------------- End of Ajax code ----------------------------
return true;
}); //------------ End of View ticket button --------------------------
//------------------------------ End of complete Jquery document function ---------------------------------------------------
});
function collectFields()
{
var elements = document.CreateForm.elements;
var pairs = new Array();
for (var i = 0; i < elements.length; i++) {
if ((name = elements[i].name) && (value = elements[i].value))
pairs.push(name + "=" + encodeURIComponent(value)); }
return pairs.join("&");
}
on "submitticket" button press I am executing one AJAX script..and on "viewticket" button I am executing another AJAX script...submitbutton AJAX is working but viewticket ajax call is returning "undefined" as return text or blank...even in the corresponding php file i am just echoing "1" and check here nothing more but still result is "undefined" or blank...whats the problem? can i call AJAX like this in one file? if yes then why my code is not working..please suggest i would appreciate.
thanks