Rohitashv Singhal
Rohitashv Singhal

Reputation: 4557

Return value in Jquery Ajax

I am working on jquery ajax. I am using the code as follow :

var url = baseurl +"/index.php/users/ajaxwixusers";
    var dataStringfirst = 'wixuserid='+ instanceId;
    $.ajax({
            //dataType : 'html',
            type: 'GET',
            url : url,
            data : dataStringfirst,
            complete : function() { },
            success: function(data) 
                    {
                        alert(data);
                        window.location.href="http://localhost:81/customers/index.php/acappointments/appointuseroverlay/user_id/203";
                    }
        });

In PHP file I am getting the value as :

echo $user_id = $wixuser->id;

I want to return ths value on success. When I am trying to alert the output of ajax.

It is returning the complete HTML of the file. How can I return only value instead of complete HTML?

Upvotes: 1

Views: 233

Answers (2)

Tej
Tej

Reputation: 11

Ajax response always gives complete data as output from requested page and If you don't want to use HTML then why you are placing it there? If you want to get any specific value then Print that value only don't use HTML on that page.

Upvotes: 0

Telvin Nguyen
Telvin Nguyen

Reputation: 3559

It returned complete HTML because your app kept running and rendering the rest of the request after your echo command. You should add one line exit instead.

exit();

Upvotes: 3

Related Questions