Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8414813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:15:47+00:00 2026-06-10T01:15:47+00:00

When using jquery with php, is it possible to send data as HTML but

  • 0

When using jquery with php, is it possible to send data as HTML but receive data back as json? In my case i’m sending form data as HTML since json can only handle alphanumeric data. If the form contained error, an array of error messages is returned, which I’ll append to error message divs, if not, the user is redirected. Is it possible to do this? What datatype should I specify and should I return the array using json_encode

$("#sform").submit(function() {
    $.ajax({
        type: "POST",
        data: $(#sform).serialize(),
        cache: false,
        //What data type to sepcify here? Data goes as HTML but returns as json
        url: "user_verify.php",
        success: function(data) {
            //Print the php arrays data here to errormessage divs
        }
    });
    return false;
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:15:48+00:00Added an answer on June 10, 2026 at 1:15 am

    To tell the server what type of data you’re expecting back, use the dataType argument:

    $("#sform").submit(function() {
        $.ajax({
            type: "POST",
            data: $(#sform).serialize(),
            cache: false,
            dataType: 'json',
            url: "user_verify.php",
            success: function(data) {
                //Print the php arrays data here to errormessage divs
            }
        });
        return false;
    });
    

    If you don’t specify dataType then $.ajax will try to guess the type based on the header sent back from the server.

    In your case, you can also add this to your php page:

    header('Content-type: application/json');
    

    and as you stated, return your data with json_encode().

    If you don’t to POST data, you can also check out the getJSON() method: http://api.jquery.com/jQuery.getJSON/

    note: using dataType AND setting the content-type to application/json may be redundant, but it can add clarity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write JSON data to a text file using jQuery and PHP.
I'm posting data using jquery/ajax and PHP at the backend. Problem being, when I
using jquery's .post i send do my php code an object that with var_dump
Background: Using jQuery 1.7 client side PHP server side Using json responses with json_encode
Is this possible using jQuery/PHP? I am looking to have my webpage automatically go
Is this possible to get result from a php file without using jQuery ?
I'm making a chat script using jQuery and JSON, but my hosting suspends it
I've got a problem sending a file to a serverside PHP-script using jQuery's ajax
Possible Duplicate: using jquery $.ajax to call a PHP function I need to call
I am using jquery to post vars to a php script. Is it possible

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.