0

I was testing 2 ways(sever and client side) to call javascript AJAX to post a ticket to website and then get a link of ticket number for tracking/edit/etc $('#output').html(a);. However both of them got a different results.

Server side button clicked is able to call CreateIsm() and got a link of ticket number $('#output').html(a); but couldn't get and pass textarea value to ticket detail info which it empty or null. The alert message in success function under AJAX was successful

Client side button clicked is able to call CreateIsm() but couldn't get a link of ticket number but able to get and pass textarea value to ticket detail info. The alert does not trigger in success function under AJAX and I don't know why. Anyone know why?

I want the result is successful pass information to ticket detail from textarea AND get a link of ticket number.

Here a javascript function,

<script>

    // global variables
    id = '<%= AD.NEAt.GetUserID().ToString() %>';
    notes = '';
    ismClassId = '';
    caseType = '';
    l1 = '';
    l2 = '';
    l3 = '';


      // Create ISM Ticket
   $('#ButtonRequest').click(function () {

     //var textBox = document.getElementById('<%=txt.ClientID %>'); //This Freeze
    //var textBox = document.getElementById('#txt'); //does not appear in ticket detail
    //var textBox = $('<%=txt.ClientID %>').val(); //does not appear in ticket detail
    //var textBox = "Please add the following DNS entries\n"; appear in ticket detail

        ismClassId = 'DOW31038';
        caseType = 'Request';
        l1 = 'Request';
        l2 = 'Network';
        l3 = 'Static IP Address';

        //This one worked for client side. To get ip and name!
        notes = $('#txt').val();

        $.support.cors = true;
        $.ajax({
            type: "POST",
            url: "http://servername/Common/Components/ISM/SubmissionPage.aspx",
            data: {
                'Form_ID': '08.01.7',
                'ISM_Class_ID': ismClassId,
                'Case_Type': caseType,
                'Level_1': l1,
                'Level_2': l2,
                'Level_3': l3,
                'Case_Notes': notes,
                'Contact_ID': id
            },
            success: function (data) {
                //console.log(data);
                alert("success function called");
                var str = data;
                var ticket = $(str).find("#ticketIDOutput").val();
                var hreff = "http://servername/Form/SRApproval/SRApproval.aspx?ticketID=" + ticket;
                var a = "<a href='" + hreff + "' target='blank'>" + ticket + "</a> created."
                $('#output').html(a);

            },
            error: function (jqXHR, textStatus, errorThrown) {

                $('#output').html("Error creating ISM ticket: " + textStatus + " - " + errorThrown);
            }
        });

    });  

</script>

C# server side execute when user click the button,

protected void ButtonRequest_Click(object sender, EventArgs e)
    {
       //more codes above
 //ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "call", "<script>CreateIsm();</script>", false);
}

ASPX client-side to trigger when the user click the button,

<asp:Button ID="ButtonRequest" runat="server" onclick="ButtonRequest_Click" OnClientClick="return false" UseSubmitBehavior="false"
            Text="Request" Visible="False" style="height: 26px" />
        <br />

The textarea that is suppose to be send to ticket detail info,

<asp:TextBox ID="txt" runat="server" visible="False" TextMode="MultiLine" 
            Width=356px Height=200px style="margin-left: 0px"></asp:TextBox>

1 Answer 1

1

$(str).find() I don't think this line makes any sense. Just above you did var str = data...Why are you looking for an item on the page called data/str???

Also, do not do ScriptManager script attaching.

set OnClientClick="return false" on the button to prevent postback, then use $(button).click() in jQuery to do your AJAX.

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

7 Comments

You mean create $(button.click() inside CreateIsm() and have AJAX function inside the $(button.click()?
No. Destroy CreateIsm(). Write like this: $('#ButtonRequest').click(function(){ //stuff from inside CreateIsm here });
I tried that. It doesn't trigger anything at all when clicked. Then I removed the OnClientClick="return false". Only C# server side button was triggered but not $("#ButtonRequest'").click(function()
This means you have a spelling mistake, $("#ButtonRequest'") has too many quotes already. Easier to see with single quotes $('#ButtonRequest'). Keep OnClientClick="return false".
I did that. Still doesn't trigger it. I edited my code above from your example.
|

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.