1

Hi i have post form in jquery with php , the form call other page and get the result with json from jquery , for example when i use jquery and call to this page in php i get this for read json from jquery :

<?php
print '{"login":"datos_fails_lock"}';
?>

The problem in this case it´s i can only show this and no include other text in the results , if include more os this code the script no works , i like json detect this code but also i want show html and at the moment i can´t do this

It´s posible when i call other page from form of jquery i can include other informations as html and works json from this page

Sorry i explain the best i can

Regards !

4 Answers 4

1

Instead of printing your own json text layout, why not use PHP json_encode to do it for you. that way you can have the array you want including html and have that function encode it.

Example:

<?php
print json_encode(array('login' => 'datos_fails_lock'));
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Can you put example of code for i see and create other , thank´s :)
0

At the PHP side:

<?php
  // compute html
  $html = '<div><p>...</p></div>';
  // compute json
  $json = '{"login":"datos_fails_lock"}';

  $response = array('html' => $html, 'json' => $json);
  print json_encode($response);
?>

At the JavaScript side:

var response = JSON.parse( xhr.responseText );

// append html to a div
$( '#response' ).html( response.html );
// parse json response
var jsonObj = JSON.parse( response.json );

Comments

0

To the best I can understand, if you are looking to get json encoded values from your php file and show with jquery that called the file you do something like:

In you php file:

<?
  echo json_encode(array(
    'login' => 'datos_fails_lock',
    'something_else' => 'Other thing'
  ));
?>

and from jQuery if it is post submission, you can use some thing like:

$.post('ajax/process.php', function(data) {
  $('.result').html(data.login);
  $('.other_thing').html(data.something_else);
});

Comments

0

The best inline solution:

<?php
    $myObjectOrArray = (object) array('test' => array('test' => array('test' => 'testValue')));
    $javascriptGateway = rawurlencode(json_encode(myObjectOrArray));
?>

<script type="text/javascript">
    //<!--
         var myObjectOrArray = JSON.stringify(unescape('<?php echo $javascriptGateway;?>'));
         alert(myObjectOrArray.test.test.test); //result: testValue
    //-->
</script>

I use this solution so I can pass my php object containing special char into a javascript object.

Comments

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.